add clear
This commit is contained in:
+19
-34
@@ -7,7 +7,12 @@
|
||||
*/
|
||||
|
||||
namespace wchat;
|
||||
class Account extends Miniprogarampage
|
||||
|
||||
use common\Decode;
|
||||
use common\HttpClient;
|
||||
use common\Result;
|
||||
|
||||
class Account extends SmallProgram
|
||||
{
|
||||
|
||||
private $wxaqr = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=';
|
||||
@@ -43,7 +48,7 @@ class Account extends Miniprogarampage
|
||||
$param['js_code'] = $code;
|
||||
$param['grant_type'] = 'authorization_code';
|
||||
|
||||
$this->request->setMethod(WxClient::GET);
|
||||
$this->request->setMethod(HttpClient::GET);
|
||||
$this->request->addHeader('Content-Type', 'text/xml');
|
||||
|
||||
return $this->request->get('sns/jscode2session', $param);
|
||||
@@ -58,11 +63,11 @@ class Account extends Miniprogarampage
|
||||
{
|
||||
$query = [
|
||||
'access_token' => $this->getAccessToken(),
|
||||
'openid' => $openid,
|
||||
'lang' => 'zh_CN'
|
||||
'openid' => $openid,
|
||||
'lang' => 'zh_CN'
|
||||
];
|
||||
|
||||
$this->request->setMethod(WxClient::GET);
|
||||
$this->request->setMethod(HttpClient::GET);
|
||||
$this->request->setIsSSL(true);
|
||||
return $this->request->get($this->publicInfo, $query);
|
||||
}
|
||||
@@ -84,33 +89,13 @@ class Account extends Miniprogarampage
|
||||
*/
|
||||
public function decode($encryptedData, $iv, $sessionKey, $asArray = false)
|
||||
{
|
||||
$config = Wx::getMiniProGaRamPage()->getConfig();
|
||||
if (strlen($sessionKey) != 24) {
|
||||
throw new \Exception('encodingAesKey 非法', $this->IllegalAesKey);
|
||||
}
|
||||
$decode = new Decode();
|
||||
$decode->setSessionKey($sessionKey);
|
||||
$decode->setEncryptedData($encryptedData);
|
||||
$decode->setAppId($this->config->getAppid());
|
||||
$decode->setIv($iv);
|
||||
|
||||
$aesKey = base64_decode($sessionKey);
|
||||
if (strlen($iv) != 24) {
|
||||
throw new \Exception('base64解密失败', $this->IllegalIv);
|
||||
}
|
||||
|
||||
$aesIV = base64_decode($iv);
|
||||
$aesCipher = base64_decode($encryptedData);
|
||||
$result = openssl_decrypt($aesCipher, "AES-128-CBC", $aesKey, OPENSSL_RAW_DATA, $aesIV);
|
||||
if ($result === false) {
|
||||
throw new \Exception('aes 解密失败', $this->IllegalBuffer);
|
||||
}
|
||||
|
||||
$dataObj = json_decode($result);
|
||||
if ($dataObj->watermark->appid != $config->getAppid()) {
|
||||
throw new \Exception('aes 解密失败', $this->IllegalBuffer);
|
||||
}
|
||||
|
||||
if ($asArray) {
|
||||
return get_object_vars($dataObj);
|
||||
}
|
||||
|
||||
return $dataObj;
|
||||
return $decode->decode($asArray);
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +112,7 @@ class Account extends Miniprogarampage
|
||||
$sendBody['path'] = $path;
|
||||
$sendBody['width'] = $width;
|
||||
|
||||
$this->request->setMethod(WxClient::POST);
|
||||
$this->request->setMethod(HttpClient::POST);
|
||||
$this->request->setCallback([$this, 'saveByPath']);
|
||||
|
||||
return $this->request->post($url, $sendBody);
|
||||
@@ -155,7 +140,7 @@ class Account extends Miniprogarampage
|
||||
|
||||
$url = $this->getwxacode . $this->getAccessToken();
|
||||
|
||||
$this->request->setMethod(WxClient::POST);
|
||||
$this->request->setMethod(HttpClient::POST);
|
||||
$this->request->setCallback([$this, 'saveByPath']);
|
||||
return $this->request->post($url, $sendBody);
|
||||
}
|
||||
@@ -182,7 +167,7 @@ class Account extends Miniprogarampage
|
||||
|
||||
$url = $this->getwxacodeunlimit . $this->getAccessToken();
|
||||
|
||||
$this->request->setMethod(WxClient::POST);
|
||||
$this->request->setMethod(HttpClient::POST);
|
||||
$this->request->setCallback([$this, 'saveByPath']);
|
||||
return $this->request->post($url, $sendBody);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user