autojs QQ群post签到(四)

接着上一篇autojs QQ群post签到(三)

今天我们来实现webview的cookie管理器提取skey和p_skey

"ui";
ui.layout(
  
      
          
              
          
      
  
)
var url = 'https://user.qzone.qq.com'
ui.webview.loadUrl(url);
var ck = getCookie()
log(ck)
var skeyAndP_skey = extrackSkeyAndP_skey(ck)
log(skeyAndP_skey)

function getCookie() {
  http.__okhttp__.muteClient(new OkHttpClient.Builder().cookieJar(web.webkitCookieJar))
  var cookieManager = web.cookieManager;
  var ck = cookieManager.getCookie(url)
  return ck
}

function extrackSkeyAndP_skey(ck) {
  var keyReg = /(skey|p_skey)=.+?(;|$)/g
  var key = ck.match(keyReg)
  var skey = null;
  var p_skey = null;
  for (let i = 0; i < key.length; i++) {
    var v = key[i]
    var newArr = v.split('=')
    if (newArr[0] == "skey") {
      skey = newArr[1]
    } else if (newArr[0] == "p_skey") {
      p_skey = newArr[1]
    } else {
      alert('好像是其他怪怪的东西,你自己写cookie提取key吧')
      log(ck)
      exit()
    }
  }
  var result = {
    skey: skey.substr(0, skey.length - 1),
    p_skey: p_skey.replace(';', '')
  }
  return result
}

你可能感兴趣的:(autojs QQ群post签到(四))