Commit 1c0a09fa by yeran

update 201804518

1 parent 84e36693
File mode changed
File mode changed
File mode changed
File mode changed
File mode changed
File mode changed
File mode changed
File mode changed
File mode changed
File mode changed
File mode changed
File mode changed
File mode changed
File mode changed
File mode changed
...@@ -13,18 +13,24 @@ class Config{ ...@@ -13,18 +13,24 @@ class Config{
'key_file'=>null, 'key_file'=>null,
'token'=>null, 'token'=>null,
'encodingAesKey'=>null, 'encodingAesKey'=>null,
'accessToken' => '',
'open'=>[ 'open'=>[
'appid'=>'', 'appid'=>'',
'secret'=>'', 'secret'=>'',
'token'=>null, 'token'=>null,
'encodingAesKey'=>null, 'encodingAesKey'=>null,
'componentAccessToken'=>''
], ],
'webLogin'=>[ 'webLogin'=>[
'appid'=>'', 'appid'=>'',
'secret'=>'' 'secret'=>''
] ]
]; ];
static public $type = 'O';
static public $config = [
'cachePath' => APP_ROOT.'/cache/file/%s', //%s 为APPID替代 此公众号下所有凭证都会缓存在此目录下
'cacheTime' => '7000', //缓存有效时间
];
/** /**
* *
* 第三方授权维护服务的链接 * 第三方授权维护服务的链接
...@@ -43,15 +49,9 @@ class Config{ ...@@ -43,15 +49,9 @@ class Config{
'openHandler'=>'O', //开放平台接入 'openHandler'=>'O', //开放平台接入
'mpHandler'=>'A' //普通接入 'mpHandler'=>'A' //普通接入
]; ];
static public $type;
static public $config = [
'cachePath' => APP_ROOT.'/cache/file/%s', //%s 为APPID替代 此公众号下所有凭证都会缓存在此目录下
'cacheTime' => '7000', //缓存有效时间
];
static public $accessToken;
static public $jsApiTicket; static public $jsApiTicket;
static public $oAuthAccessToken; static public $oAuthAccessToken;
static public $componentAccessToken;
static public $CARDJSTICKET; static public $CARDJSTICKET;
} }
\ No newline at end of file
File mode changed
File mode changed
File mode changed
File mode changed
File mode changed
...@@ -24,18 +24,22 @@ class CryptMsg ...@@ -24,18 +24,22 @@ class CryptMsg
private $encodingAesKey; private $encodingAesKey;
private $appId; private $appId;
/**
* 构造函数
* @param $token string 公众平台上,开发者设置的token
* @param $encodingAesKey string 公众平台上,开发者设置的EncodingAESKey /**
* @param $appId string 公众平台的appId * 构造函数
*/ * @param $token string 公众平台上,开发者设置的token
public function WXBizMsgCrypt($token, $encodingAesKey, $appId) * @param $encodingAesKey string 公众平台上,开发者设置的EncodingAESKey
{ * @param $appId string 公众平台的appId
$this->token = $token; */
$this->encodingAesKey = $encodingAesKey; public function WXBizMsgCrypt($token, $encodingAesKey, $appId)
$this->appId = $appId; {
} $this->token = $token;
$this->encodingAesKey = $encodingAesKey;
$this->appId = $appId;
}
/** /**
* 将公众平台回复用户的消息加密打包. * 将公众平台回复用户的消息加密打包.
......
File mode changed
...@@ -60,90 +60,150 @@ class Prpcrypt ...@@ -60,90 +60,150 @@ class Prpcrypt
{ {
public $key; public $key;
function Prpcrypt($k) function __construct($k)
{ {
$this->key = base64_decode($k . "="); $this->key = base64_decode($k . "=");
} }
/** /**
* 对明文进行加密 * 加密方法
* @param string $text 需要加密的明文 * @param string $text
* @return string 加密后的密文 * @param $appid
*/ * @return string
public function encrypt($text, $appid) */
{ public function encrypt($text,$appid) {
try {
try { //获得16位随机字符串,填充到明文之前
//获得16位随机字符串,填充到明文之前 $random = $this->getRandomStr();//"aaaabbbbccccdddd";
$random = $this->getRandomStr(); $text = $random . pack("N", strlen($text)) . $text . $appid;
$text = $random . pack("N", strlen($text)) . $text . $appid; $iv = substr($this->key, 0, 16);
// 网络字节序 $pkc_encoder = new PKCS7Encoder;
$size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $text = $pkc_encoder->encode($text);
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); $encrypted = openssl_encrypt($text,'AES-256-CBC',substr($this->key, 0, 32),OPENSSL_ZERO_PADDING,$iv);
$iv = substr($this->key, 0, 16); return array(ErrorCode::$OK, $encrypted);
//使用自定义的填充方式对明文进行补位填充 } catch (Exception $e) {
$pkc_encoder = new PKCS7Encoder; //print $e;
$text = $pkc_encoder->encode($text); return array(ErrorCode::$EncryptAESError, null);
mcrypt_generic_init($module, $this->key, $iv); }
//加密 }
$encrypted = mcrypt_generic($module, $text);
mcrypt_generic_deinit($module); /**
mcrypt_module_close($module); * 解密方法
* @param string $encrypted
//print(base64_encode($encrypted)); * @param $appid
//使用BASE64对加密后的字符串进行编码 * @return string
return array(ErrorCode::$OK, base64_encode($encrypted)); */
} catch (Exception $e) { public function decrypt($encrypted,$appid) {
//print $e; try {
return array(ErrorCode::$EncryptAESError, null); $iv = substr($this->key, 0, 16);
} $decrypted = openssl_decrypt($encrypted,'AES-256-CBC',substr($this->key, 0, 32),OPENSSL_ZERO_PADDING,$iv);
} } catch (Exception $e) {
return array(ErrorCode::$DecryptAESError, null);
/** }
* 对密文进行解密 try {
* @param string $encrypted 需要解密的密文 //去除补位字符
* @return string 解密得到的明文 $pkc_encoder = new PKCS7Encoder;
*/ $result = $pkc_encoder->decode($decrypted);
public function decrypt($encrypted, $appid) //去除16位随机字符串,网络字节序和AppId
{ if (strlen($result) < 16)
return "";
try { $content = substr($result, 16, strlen($result));
//使用BASE64对需要解密的字符串进行解码 $len_list = unpack("N", substr($content, 0, 4));
$ciphertext_dec = base64_decode($encrypted); $xml_len = $len_list[1];
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); $xml_content = substr($content, 4, $xml_len);
$iv = substr($this->key, 0, 16); $from_appid = substr($content, $xml_len + 4);
mcrypt_generic_init($module, $this->key, $iv); if (!$appid)
$appid = $from_appid;
//解密 //如果传入的appid是空的,则认为是订阅号,使用数据中提取出来的appid
$decrypted = mdecrypt_generic($module, $ciphertext_dec); } catch (Exception $e) {
mcrypt_generic_deinit($module); //print $e;
mcrypt_module_close($module); return array(ErrorCode::$IllegalBuffer, null);
} catch (Exception $e) { }
return array(ErrorCode::$DecryptAESError, null); if ($from_appid != $appid)
} return array(ErrorCode::$ValidateAppidError, null);
//不注释上边两行,避免传入appid是错误的情况
return array(0, $xml_content, $from_appid);
try { }
//去除补位字符
$pkc_encoder = new PKCS7Encoder; // /**
$result = $pkc_encoder->decode($decrypted); // * 对明文进行加密
//去除16位随机字符串,网络字节序和AppId // * @param string $text 需要加密的明文
if (strlen($result) < 16) // * @return string 加密后的密文
return ""; // */
$content = substr($result, 16, strlen($result)); // public function encrypt($text, $appid)
$len_list = unpack("N", substr($content, 0, 4)); // {
$xml_len = $len_list[1]; //
$xml_content = substr($content, 4, $xml_len); // try {
$from_appid = substr($content, $xml_len + 4); // //获得16位随机字符串,填充到明文之前
} catch (Exception $e) { // $random = $this->getRandomStr();
//print $e; // $text = $random . pack("N", strlen($text)) . $text . $appid;
return array(ErrorCode::$IllegalBuffer, null); // // 网络字节序
} // $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
if ($from_appid != $appid) // $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
return array(ErrorCode::$ValidateAppidError, null); // $iv = substr($this->key, 0, 16);
return array(0, $xml_content); // //使用自定义的填充方式对明文进行补位填充
// $pkc_encoder = new PKCS7Encoder;
} // $text = $pkc_encoder->encode($text);
// mcrypt_generic_init($module, $this->key, $iv);
// //加密
// $encrypted = mcrypt_generic($module, $text);
// mcrypt_generic_deinit($module);
// mcrypt_module_close($module);
//
// //print(base64_encode($encrypted));
// //使用BASE64对加密后的字符串进行编码
// return array(ErrorCode::$OK, base64_encode($encrypted));
// } catch (Exception $e) {
// //print $e;
// return array(ErrorCode::$EncryptAESError, null);
// }
// }
// /**
// * 对密文进行解密
// * @param string $encrypted 需要解密的密文
// * @return string 解密得到的明文
// */
// public function decrypt($encrypted, $appid)
// {
//
// try {
// //使用BASE64对需要解密的字符串进行解码
// $ciphertext_dec = base64_decode($encrypted);
// $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
// $iv = substr($this->key, 0, 16);
// mcrypt_generic_init($module, $this->key, $iv);
//
// //解密
// $decrypted = mdecrypt_generic($module, $ciphertext_dec);
// mcrypt_generic_deinit($module);
// mcrypt_module_close($module);
// } catch (Exception $e) {
// return array(ErrorCode::$DecryptAESError, null);
// }
//
//
// try {
// //去除补位字符
// $pkc_encoder = new PKCS7Encoder;
// $result = $pkc_encoder->decode($decrypted);
// //去除16位随机字符串,网络字节序和AppId
// if (strlen($result) < 16)
// return "";
// $content = substr($result, 16, strlen($result));
// $len_list = unpack("N", substr($content, 0, 4));
// $xml_len = $len_list[1];
// $xml_content = substr($content, 4, $xml_len);
// $from_appid = substr($content, $xml_len + 4);
// } catch (Exception $e) {
// //print $e;
// return array(ErrorCode::$IllegalBuffer, null);
// }
// if ($from_appid != $appid)
// return array(ErrorCode::$ValidateAppidError, null);
// return array(0, $xml_content);
//
// }
/** /**
......
File mode changed
...@@ -17,16 +17,23 @@ class XMLParse ...@@ -17,16 +17,23 @@ class XMLParse
public function extract($xmltext) public function extract($xmltext)
{ {
try { try {
$xml = new DOMDocument(); $xml = new DOMDocument();
$xml->loadXML($xmltext); $xml->loadXML($xmltext);
$array_e = $xml->getElementsByTagName('Encrypt'); $array_e = $xml->getElementsByTagName('Encrypt');
$array_a = $xml->getElementsByTagName('ToUserName'); $array_a = $xml->getElementsByTagName('ToUserName');
$encrypt = $array_e->item(0)->nodeValue; $encrypt = $array_e->item(0)->nodeValue;
$tousername = $array_a->item(0)->nodeValue; $tousername = null;
if(!empty($array_a) && $array_a->item(0)){
$tousername = $array_a->item(0)->nodeValue;
}
return array(0, $encrypt, $tousername); return array(0, $encrypt, $tousername);
} catch (Exception $e) { } catch (Exception $e) {
//debug($e); //debug($e);
//print $e . "\n"; //print $e . "\n";
debug($e->getMessage());
return array(ErrorCode::$ParseXmlError, null, null); return array(ErrorCode::$ParseXmlError, null, null);
} }
} }
......
File mode changed
File mode changed
File mode changed
...@@ -16,12 +16,12 @@ class WXBizDataCrypt ...@@ -16,12 +16,12 @@ class WXBizDataCrypt
private $appid; private $appid;
private $sessionKey; private $sessionKey;
/** /**
* 构造函数 * 构造函数
* @param $sessionKey string 用户在小程序登录后获取的会话密钥 * @param $sessionKey string 用户在小程序登录后获取的会话密钥
* @param $appid string 小程序的appid * @param $appid string 小程序的appid
*/ */
public function WXBizDataCrypt( $appid, $sessionKey) public function __construct( $appid, $sessionKey)
{ {
$this->sessionKey = $sessionKey; $this->sessionKey = $sessionKey;
$this->appid = $appid; $this->appid = $appid;
......
File mode changed
<?php <?php
namespace wechatkit\HttpFul; namespace wechatkit\HttpFul;
use wechatkit\Config\Config, \Httpful\Request; use Httpful\Request;
use wechatkit\Config\Config;
class HttpFul implements \wechatkit\Core\HttpFul
{ class HttpFul implements \wechatkit\Core\HttpFul
{
public $accessToken = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%1%&secret=%2%'; public $accessToken = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%1%&secret=%2%';
public $jsApiTicket = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%1%&type=jsapi'; public $jsApiTicket = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%1%&type=jsapi';
public $oAuth2AccessTokenUserInfo = 'https://api.weixin.qq.com/sns/userinfo?access_token=%1%&openid=%2%&lang=zh_CN '; public $oAuth2AccessTokenUserInfo = 'https://api.weixin.qq.com/sns/userinfo?access_token=%1%&openid=%2%&lang=zh_CN ';
public $oauth2AccessToken = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=%1%&secret=%2%&code=%3%&grant_type=authorization_code '; public $oauth2AccessToken = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=%1%&secret=%2%&code=%3%&grant_type=authorization_code ';
public $openOauth2AccessToken = 'https://api.weixin.qq.com/sns/oauth2/component/access_token?appid=%1%&code=%2%&grant_type=authorization_code&component_appid=%3%&component_access_token=%4%'; public $openOauth2AccessToken = 'https://api.weixin.qq.com/sns/oauth2/component/access_token?appid=%1%&code=%2%&grant_type=authorization_code&component_appid=%3%&component_access_token=%4%';
public $apiComponentToken = 'https://api.weixin.qq.com/cgi-bin/component/api_component_token'; public $apiComponentToken = 'https://api.weixin.qq.com/cgi-bin/component/api_component_token';
public $apiAuthorizerToken = 'https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=%1%'; public $apiAuthorizerToken = 'https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=%1%';
public $preAuthCode = 'https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=%1%'; public $preAuthCode = 'https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=%1%';
public $apiQueryAuth = 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=%1%'; public $apiQueryAuth = 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=%1%';
public $apiGetAuthorizerInfo = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=%1%'; public $apiGetAuthorizerInfo = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=%1%';
public $uploadimg = 'https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=%1%'; public $uploadimg = 'https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=%1%';
public $shakearoundMaterialAdd = 'https://api.weixin.qq.com/shakearound/material/add?access_token=%1%&type=%2%'; public $shakearoundMaterialAdd = 'https://api.weixin.qq.com/shakearound/material/add?access_token=%1%&type=%2%';
public $card = 'https://api.weixin.qq.com/card/create?access_token=%1%'; public $card = 'https://api.weixin.qq.com/card/create?access_token=%1%';
public $applyid = 'https://api.weixin.qq.com/shakearound/device/applyid?access_token=%1%'; public $applyid = 'https://api.weixin.qq.com/shakearound/device/applyid?access_token=%1%';
public $applystatus = 'https://api.weixin.qq.com/shakearound/device/applystatus?access_token=%1%'; public $applystatus = 'https://api.weixin.qq.com/shakearound/device/applystatus?access_token=%1%';
public $deviceSearch = 'https://api.weixin.qq.com/shakearound/device/search?access_token=%1%'; public $deviceSearch = 'https://api.weixin.qq.com/shakearound/device/search?access_token=%1%';
public $pageAdd = 'https://api.weixin.qq.com/shakearound/page/add?access_token=%1%'; public $pageAdd = 'https://api.weixin.qq.com/shakearound/page/add?access_token=%1%';
public $pageUpdate = 'https://api.weixin.qq.com/shakearound/page/update?access_token=%1%'; public $pageUpdate = 'https://api.weixin.qq.com/shakearound/page/update?access_token=%1%';
public $deviceeBindpage = 'https://api.weixin.qq.com/shakearound/device/bindpage?access_token=%1%'; public $deviceeBindpage = 'https://api.weixin.qq.com/shakearound/device/bindpage?access_token=%1%';
public $getshakeinfo = 'https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token=%1%'; public $getshakeinfo = 'https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token=%1%';
public $promotion = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers'; public $promotion = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
//公众号红包 //公众号红包
public $sendredpack = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack'; public $sendredpack = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack';
public $getticketCard = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%1%&type=wx_card'; public $getticketCard = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%1%&type=wx_card';
public $unifiedorder = 'https://api.mch.weixin.qq.com/pay/unifiedorder'; public $unifiedorder = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
//小程序获取用户 //小程序获取用户
public $openOauth2JSAccessToken = 'https://api.weixin.qq.com/sns/jscode2session?appid=%1%&secret=%2%&js_code=%3%&grant_type=authorization_code'; public $openOauth2JSAccessToken = 'https://api.weixin.qq.com/sns/jscode2session?appid=%1%&secret=%2%&js_code=%3%&grant_type=authorization_code';
static public $self = NULL; //小程序第三方授权获取登陆
public $thirdOauth2JsAccessToken = 'https://api.weixin.qq.com/sns/component/jscode2session?appid=%1%&js_code=%2%&grant_type=authorization_code&component_appid=%3%&component_access_token=%4%';
static public function init()
{ static public $self = NULL;
if (NULL == self::$self) {
return new HttpFul(); static public function init()
} else { {
return self::$self; if (NULL == self::$self) {
} self::$self = new HttpFul();
} }
return self::$self;
/** }
* @param $name
* @param array $args /**
* @param string $method * @param $name
* @return bool|mixed * @param array $args
*/ * @param string $method
public function handler($name, array $args, $body=[],$bodyType='JSON', $method = 'GET',$ca=[]) * @return bool|mixed
{ */
if ($this->$name) { public function handler($name, array $args, $body=[],$bodyType='JSON', $method = 'GET',$ca=[])
switch ($method){ {
case 'GET': //if ($this->$name)
return $ret = $this->httpGet($name, $args); {
break; switch ($method){
case 'POST': case 'GET':
if('JSON' == $bodyType){ return $ret = $this->httpGet($name, $args);
$body = json_encode($body,JSON_UNESCAPED_UNICODE); break;
$body = str_replace(' ','',$body); case 'POST':
} if('JSON' == $bodyType){
return $ret = $this->httpPost($name, $args,$body,$bodyType); $body = json_encode($body,JSON_UNESCAPED_UNICODE);
break; $body = str_replace(' ','',$body);
case 'FILE': }
return $ret = $this->httpFile($name, $args,$body); return $ret = $this->httpPost($name, $args,$body,$bodyType);
break; break;
case 'CA': case 'FILE':
return $ret = $this->httpCa($name,$body,$ca); return $ret = $this->httpFile($name, $args,$body);
break; break;
} case 'CA':
return $ret = $this->httpCa($name,$body,$ca);
} else { break;
return FALSE; }
}
} }
}
/**
* @param $urlName /**
* @param $args * @param $urlName
* @return bool|mixed * @param $args
* @throws \Httpful\Exception\ConnectionErrorException * @return bool|mixed
*/ * @throws \Httpful\Exception\ConnectionErrorException
public function httpGet($urlName, $args) */
{ public function httpGet($urlName, $args)
$searchArr = []; {
for ($i = 1; $i <= count($args); $i++) { debug('----'.$this->$urlName);
$searchArr[] = '%' . $i . '%'; $searchArr = [];
} for ($i = 1; $i <= count($args); $i++) {
$url = str_replace($searchArr, $args, $this->$urlName); $searchArr[] = '%' . $i . '%';
$response = Request::get($url) }
->withStrictSSL() if(startWith($urlName,'http')){
->send(); $url = str_replace($searchArr, $args, $urlName);
}else {
$url = str_replace($searchArr, $args, $this->$urlName);
return $this->responseHandler($response, $urlName); }
} $response = Request::get($url)
->withStrictSSL()
public function httpPost($name,$args,$body,$type){ ->send();
$searchArr = [];
for ($i = 1; $i <= count($args); $i++) { debug($url.'---'.$response);
$searchArr[] = '%' . $i . '%';
}
return $this->responseHandler($response, $urlName);
debug(serialize($body)); }
$url = str_replace($searchArr, $args, $this->$name); public function httpPost($name,$args,$body,$type){
if($type == 'JSON'){ $searchArr = [];
for ($i = 1; $i <= count($args); $i++) {
$response = Request::post($url) $searchArr[] = '%' . $i . '%';
->withStrictSSL() }
->expectsJson()
->body($body) if(startWith($name,'http')){
->send(); $url = str_replace($searchArr, $args, $name);
}elseif($type == 'XML'){ }else {
$response = Request::post($url) $url = str_replace($searchArr, $args, $this->$name);
->withStrictSSL() }
->expectsXml()
->body($body) $response = '';
->send(); if($type == 'JSON'){
}
$response = Request::post($url)
->withStrictSSL()
->expectsJson()
return $this->responseHandler($response, $name); ->body($body)
} ->send();
}elseif($type == 'XML'){
public function httpFile($name,$args,$body){ $response = Request::post($url)
$searchArr = []; ->withStrictSSL()
for ($i = 1; $i <= count($args); $i++) { ->expectsXml()
$searchArr[] = '%' . $i . '%'; ->body($body)
} ->send();
$url = str_replace($searchArr, $args, $this->$name); }
$response = \Httpful\Request::post($url) return $this->responseHandler($response, $name);
->withStrictSSL() }
->attach($body)
->send(); public function httpFile($name,$args,$body){
$searchArr = [];
debug(json_encode($response)); for ($i = 1; $i <= count($args); $i++) {
$searchArr[] = '%' . $i . '%';
return $this->responseHandler($response, $name); }
} if(startWith($name,'http')){
$url = str_replace($searchArr, $args, $name);
public function httpCa($name,$body,$ca){ }else {
debug('url:'.$this->$name); $url = str_replace($searchArr, $args, $this->$name);
debug($body); }
//debug(file_get_contents($this->$name));
$response = \Httpful\Request::post(str_replace(' ','',$this->$name)) $response = \Httpful\Request::post($url)
->authenticateWithCert($ca['cert_file'], $ca['key_file'], $ca['ca_file']) ->withStrictSSL()
->withStrictSSL() ->attach($body)
->body($body) ->send();
->send();
debug(json_encode($response));
// debug('pay_result==='.$response);
return $this->responseHandler($response, $name);
return $this->responseHandler($response, $name); }
}
public function httpCa($name,$body,$ca){
/** if(startWith($name,'http')){
* @param $response $url = str_replace('', '', $name);
* @param null $name }else {
* @return bool|mixed $url = str_replace('', '', $this->$name);
*/ }
public function responseHandler($response, $name = NULL) $response = \Httpful\Request::post($url)
{ ->authenticateWithCert($ca['cert_file'], $ca['key_file'], $ca['ca_file'])
$body = $response->raw_body; ->withStrictSSL()
->body($body)
->send();
if($this->is_Json($response->raw_body)){
$body = json_decode($response->raw_body,1);
return $this->responseHandler($response, $name);
debug($body); }
}else if($this->is_Xml($response->raw_body)){
$body = json_decode(json_encode(simplexml_load_string($response->raw_body, 'SimpleXMLElement', LIBXML_NOCDATA)),1);
debug($body); /**
}else{ * @param $response
return $body; * @param null $name
} * @return bool|mixed
*/
if (!isset($body['errcode']) || 0 == $body['errcode']) { public function responseHandler($response, $name = NULL)
if (NULL != $name) { {
return $this->filter($name, $body); $body = $response->raw_body;
} else {
return $body;
} if($this->is_Json($response->raw_body)){
} else { $body = json_decode($response->raw_body,1);
if(function_exists('debug')){
debug("[{$name}][{$body['errcode']}]{$body['errmsg']}"); }else if($this->is_Xml($response->raw_body)){
} $body = json_decode(json_encode(simplexml_load_string($response->raw_body, 'SimpleXMLElement', LIBXML_NOCDATA)),1);
return FALSE; debug($body);
} }else{
} return $body;
}
/**
* @param $obj if (!isset($body['errcode']) || 0 == $body['errcode']) {
* @return mixed if (NULL != $name) {
*/ return $this->filter($name, $body);
public function objToArray($obj) } else {
{ return $body;
return json_decode(json_encode($obj), 1); }
} } else {
if(function_exists('debug')){
/** debug("[{$name}][{$body['errcode']}]{$body['errmsg']}");
* @param $name }
* @param $resp return FALSE;
* @return mixed }
*/ }
public function filter($name, $resp)
{ /**
switch ($name) { * @param $obj
case 'accessToken': * @return mixed
return $resp['access_token']; */
break; public function objToArray($obj)
{
case 'jsApiTicket': return json_decode(json_encode($obj), 1);
return $resp['ticket']; }
break;
/**
default: * @param $name
return $resp; * @param $resp
break; * @return mixed
} */
} public function filter($name, $resp)
{
public function is_Json($string) switch ($name) {
{ case 'accessToken':
json_decode($string); return $resp['access_token'];
break;
return (json_last_error() == JSON_ERROR_NONE);
} case 'jsApiTicket':
return $resp['ticket'];
public function is_Xml($xml){ break;
$xml_parser = xml_parser_create();
if(!xml_parse($xml_parser,$xml,true)){ default:
xml_parser_free($xml_parser); return $resp;
return false; break;
}else { }
return true; }
}
} public function is_Json($string)
} {
json_decode($string);
return (json_last_error() == JSON_ERROR_NONE);
}
public function is_Xml($xml){
$xml_parser = xml_parser_create();
if(!xml_parse($xml_parser,$xml,true)){
xml_parser_free($xml_parser);
return false;
}else {
return true;
}
}
}
File mode changed
File mode changed
File mode changed
File mode changed
File mode changed
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
namespace wechatkit\Mini; namespace wechatkit\Mini;
use Lestore\Wxauthcenter\Services\AccessTokenService;
use wechatkit\HttpFul\HttpFul;
use wechatkit\Run\BaseRun;
/** /**
* *
* 微信授权登陆 * 微信授权登陆
...@@ -15,6 +19,68 @@ namespace wechatkit\Mini; ...@@ -15,6 +19,68 @@ namespace wechatkit\Mini;
* Class Login * Class Login
* @package wechatkit\Mini * @package wechatkit\Mini
*/ */
class Login{ class Login extends BaseRun{
public function mpAuthorize($jsCode){
return $this->jscode2session($jsCode);
if(!$result){
return null;
}
$openid = $result['openid'];
$session_key = $result['session_key'];
$unionid = $result['unionid'];
//执行用户信息获取
}
/**
*
* 微信小程序登陆
*
* @param $jsCode
* @return bool|mixed|null
* @internal param $appid
* @internal param $secret
*/
public function jscode2session($jsCode){
if ($jsCode){
$appid = $this->options['appid'];
$componentAppid = $this->options['open']['appid'];
$componentAccessToken = AccessTokenService::componentAccessToken($this->options);
$result = null;
if($componentAccessToken) {
$result = $this->accessTokenFromJsCode($jsCode, $appid, $componentAppid, $componentAccessToken);
}
return $result;
}
return null;
}
/**
*
* 通过微信小程序code获取用户openid
*
* @param $jsCode
* @param $appid
* @param $componentAppid
* @param $componentAccessToken
* @return bool|mixed|null
* @internal param $code
* @internal param HttpFul $httpFul
*
*/
protected function accessTokenFromJsCode($jsCode,$appid,$componentAppid,$componentAccessToken){
if(!$jsCode)
return null;
$result = HttpFul::init()->handler('thirdOauth2JsAccessToken', [$appid,$jsCode,$componentAppid,$componentAccessToken]);
return $result;
}
} }
\ No newline at end of file
File mode changed
File mode changed
File mode changed
File mode changed
...@@ -2,10 +2,12 @@ ...@@ -2,10 +2,12 @@
namespace wechatkit\Oauth2; namespace wechatkit\Oauth2;
use wechatkit\Config\Config; use Lestore\Wxauthcenter\Services\AccessTokenService;
use wechatkit\Config\Config;
use wechatkit\HttpFul\HttpFul; use wechatkit\HttpFul\HttpFul;
use wechatkit\Run\BaseRun;
class Oauth2 class Oauth2 extends BaseRun
{ {
/** /**
...@@ -42,158 +44,90 @@ ...@@ -42,158 +44,90 @@
return null; return null;
$result = $httpFul->handler('openOauth2JSAccessToken', [$appid,$secret,$code]); $result = $httpFul->handler('openOauth2JSAccessToken', [$appid,$secret,$code]);
$this->result($result);
return $result; return $result;
} }
/** /**
* 公众号授权
*
* @param $redirect_uri * @param $redirect_uri
* @param string $scope * @param string $scope
* @param string $state * @param string $state
* @param bool $auto * @param bool $auto
* @return bool|mixed * @return bool|mixed
*/ */
public function mpAuthorize_v2($redirect_uri =null, $scope = 'snsapi_userinfo', $state = '', $auto = TRUE) public function mpAuthorize($redirect_uri =null, $scope = 'snsapi_userinfo', $state = '', $auto = TRUE)
{ {
if(null == $redirect_uri){ if(null == $redirect_uri){
$redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $redirect_uri = httpType().$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
} }
if (Config::$type == 'O') { //开放平台授权 if ($this->authType == 'O') { //开放平台授权
if (!$_GET['code']) { if (!$_GET['code']) {
header('location:' . sprintf( $url = sprintf(
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s&component_appid=%s#wechat_redirect', 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s&component_appid=%s#wechat_redirect',
Config::$options['appid'], $this->options['appid'],
urlencode($redirect_uri), urlencode($redirect_uri),
$scope, $scope,
$state, $state,
Config::$options['open']['appid'] $this->options['open']['appid']
)); );
header('location:' .$url);
exit(255); exit(255);
} else { } else {
if ($auto) { if ($auto) {
$result = $this->accessTokenFormCode($_GET['code'], new HttpFul()); $result = $this->accessTokenFormCode($_GET['code']);
if(empty($result)){
return null;
}
if ('snsapi_base' == $scope) { if ('snsapi_base' == $scope) {
return $result['openid']; return $result['openid'];
} }
// asyncLog('---openid--'.json_encode($result));
$info = $this->oAuth2AccessTokenUserInfo($result['openid'], new HttpFul()); $info = $this->oAuth2AccessTokenUserInfo($result['openid'],$result['access_token']);
return $info; return $info;
} }
} }
} }
} return null;
/**
* @param $redirect_uri
* @param string $scope
* @param string $state
* @param bool $auto
* @return bool|mixed
*/
public function mpAuthorize($redirect_uri =null, $scope = 'snsapi_userinfo', $state = '', $auto = TRUE)
{
if(null == $redirect_uri){
$redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}
if (Config::$type == 'A') { //普通授权
if (!$_GET['code']) {
header('location:' . sprintf(
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect',
Config::$options['appid'],
urlencode($redirect_uri),
$scope,
$state
));
exit(255);
} else {
if ($auto) {
$result = $this->accessTokenFormCode($_GET['code'], new HttpFul());
if ('snsapi_base' == $scope) {
return $result['openid'];
}
return $this->oAuth2AccessTokenUserInfo($result['openid'], new HttpFul());
}
}
} else if (Config::$type == 'O') { //开放平台授权
if (!$_GET['code']) {
header('location:' . sprintf(
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s&component_appid=%s#wechat_redirect',
Config::$options['appid'],
urlencode($redirect_uri),
$scope,
$state,
Config::$options['open']['appid']
));
exit(255);
} else {
if ($auto) {
$result = $this->accessTokenFormCode($_GET['code'], new HttpFul());
if ('snsapi_base' == $scope) {
return $result['openid'];
}
return $this->oAuth2AccessTokenUserInfo($result['openid'], new HttpFul());
}
}
}
} }
/** /**
* @param $code *
* @param HttpFul $httpFul * 通过code获取accessToken
* @return bool|mixed *
*/ * @param $code
protected function accessTokenFormCode($code, HttpFul $httpFul) * @return bool|mixed
*/
protected function accessTokenFormCode($code)
{ {
if(Config::$type == 'A'){ $result = null;
$result = $httpFul->handler('oauth2AccessToken', [$code]); if($this->authType == 'O') {
}else{ $componentAccessToken = AccessTokenService::componentAccessToken($this->options);
$result = $httpFul->handler('openOauth2AccessToken', [Config::$options['appid'],$code,Config::$options['open']['appid'],Config::$componentAccessToken]); if (!empty($componentAccessToken)) {
} $result = HttpFul::init()->handler('openOauth2AccessToken'
, [$this->options['appid'], $code, $this->options['open']['appid'], $componentAccessToken]);
}
$this->result($result); }
return $result; return $result;
} }
/** /**
* @param $openid * @param $openid
* @param HttpFul $httpFul * @param $accessToken //登录使用的accesstoken
* @return bool|mixed * @return bool|mixed
*/ */
protected function oAuth2AccessTokenUserInfo($openid, HttpFul $httpFul) protected function oAuth2AccessTokenUserInfo($openid,$accessToken)
{ {
$result = $httpFul->handler('oAuth2AccessTokenUserInfo', [$this->access_token, $openid]); $result = HttpFul::init()->handler('oAuth2AccessTokenUserInfo', [$accessToken, $openid]);
$this->result($result);
return $result; return $result;
} }
/**
* @param array $result
*/
public function result($result)
{
if(!$result && !is_array($result)){
return false;
}
foreach ($result as $key => $value) {
$this->$key = $value;
}
}
} }
...@@ -2,17 +2,14 @@ ...@@ -2,17 +2,14 @@
namespace wechatkit\Open; namespace wechatkit\Open;
use wechatkit\Config\Config; use Lestore\Wxauthcenter\Services\AccessTokenService;
use wechatkit\Config\Config;
use wechatkit\HttpFul\HttpFul; use wechatkit\HttpFul\HttpFul;
use wechatkit\Run\BaseRun;
class Open class Open extends BaseRun
{ {
public function __construct()
{
if (Config::$type != 'O') {
throw new \Exception('this api must open type');
}
}
//网页登入 //网页登入
public function webOAuth2($url = NULL, $type = 'URL', $state = NULL, $wxLoginConfig = ['style' => 'black', public function webOAuth2($url = NULL, $type = 'URL', $state = NULL, $wxLoginConfig = ['style' => 'black',
'href' => NULL]) 'href' => NULL])
...@@ -63,33 +60,62 @@ ...@@ -63,33 +60,62 @@
} }
//微信公众号授权e /**
public function authorizer($url=null){ * 微信公众号/小程序授权
if(!$_GET['auth_code']){ * @param $authType 1则商户扫码后,手机端仅展示公众号、2表示仅展示小程序,3表示公众号和小程序都展示,如果为未指定,则默认小程序和公众号都展示
$preAuthCode = HttpFul::init()->handler('preAuthCode',[Config::$componentAccessToken],['component_appid'=>Config::$options['open']['appid']],'JSON','POST'); * @param null $url
if($preAuthCode){ * @return bool|mixed
if(null == $url){ */
public function authorizer($authType=3,$url=null){
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'; if(!array_key_exists('auth_code',$_GET) || !$_GET['auth_code']){
$url = $http_type.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $componentAppid = $this->options['open']['appid'];
$componentToken = AccessTokenService::componentAccessToken($this->options);
if(empty($componentToken)){
return false;
}
$preAuthCode = HttpFul::init()->handler('preAuthCode'
,[$componentToken]
,['component_appid'=>$componentAppid],'JSON','POST');
if($preAuthCode){
if(null == $url){
$url = httpType().$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
} }
header(sprintf('Location:https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=%s&pre_auth_code=%s&redirect_uri=%s',Config::$options['open']['appid'],$preAuthCode['pre_auth_code'],urlencode($url))); $url = sprintf('Location:https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=%s&pre_auth_code=%s&redirect_uri=%s'
exit(255); ,$componentAppid,$preAuthCode['pre_auth_code'],urlencode($url));
$url .= '&auth_type='.$authType;
header($url);
exit(255);
} }
return false;
}else{ }else{
return $this->authinfo($_GET['auth_code']); return $this->authinfo($_GET['auth_code']);
} }
} }
//拉公众号信息
/**
* 拉公众号详细信息
*
* @param $authorizer_appid
* @return bool|mixed
*/
public function mpInfo($authorizer_appid){ public function mpInfo($authorizer_appid){
//$apiGetAuthorizerInfo
return HttpFul::init()->handler('apiGetAuthorizerInfo',[Config::$componentAccessToken],['component_appid'=>Config::$options['open']['appid'],'authorizer_appid'=>$authorizer_appid],'JSON','POST'); return HttpFul::init()->handler('apiGetAuthorizerInfo',[AccessTokenService::componentAccessToken($this->options)]
,['component_appid'=>$this->options['open']['appid'],'authorizer_appid'=>$authorizer_appid],'JSON','POST');
} }
/**
* 获取公众号授权信息
* @param $auth_code
* @return bool|mixed
*/
public function authinfo($auth_code){ public function authinfo($auth_code){
return HttpFul::init()->handler('apiQueryAuth',[Config::$componentAccessToken],['component_appid'=>Config::$options['open']['appid'],'authorization_code'=>$auth_code],'JSON','POST'); return HttpFul::init()->handler('apiQueryAuth',[AccessTokenService::componentAccessToken($this->options)]
,['component_appid'=>$this->options['open']['appid'],'authorization_code'=>$auth_code],'JSON','POST');
} }
} }
\ No newline at end of file
File mode changed
<?php
/**
* Created by IntelliJ IDEA.
* User: yeran
* Date: 2018/5/14
* Time: 下午4:37
*/
namespace wechatkit\Run;
class BaseRun {
public $options;
public $authType = 'O';
public $authorizerAccessToken;
public $componentAccessToken;
public function __construct($options)
{
$this->options = $options;
}
/**
* @return mixed
*/
public function getOptions()
{
return $this->options;
}
/**
* @param mixed $options
*/
public function setOptions($options)
{
$this->options = $options;
}
/**
* @return mixed
*/
public function getAuthorizerAccessToken()
{
return $this->authorizerAccessToken;
}
/**
* @param mixed $authorizerAccessToken
*/
public function setAuthorizerAccessToken($authorizerAccessToken)
{
$this->authorizerAccessToken = $authorizerAccessToken;
}
/**
* @return mixed
*/
public function getComponentAccessToken()
{
return $this->componentAccessToken;
}
/**
* @param mixed $componentAccessToken
*/
public function setComponentAccessToken($componentAccessToken)
{
$this->componentAccessToken = $componentAccessToken;
}
}
\ No newline at end of file
<?php <?php
namespace wechatkit\Run; namespace wechatkit\Run;
use wechatkit\Config, wechatkit\AccessToken; use wechatkit\Config, wechatkit\AccessToken;
class Run implements \wechatkit\Core\Run{ class Run implements \wechatkit\Core\Run{
static $self = NULL; static $self = NULL;
static $namespace;
/**
* @param $type
* @param array $options [ appid secret mch_id key cert_file key_file ] public $options;
* @param array $config public $cacheConfig;
* @return bool
*/ /**
public function App($type, array $options = [], array $config = []) * @param $type string
{ * @param array $options [ appid secret mch_id key cert_file key_file ]
if (!in_array($type, Config\Config::$typeList)) { * @param array $config
return FALSE; * @return $this
} else { */
Config\Config::$type = $type; public function App($type, array $options = [], array $config = [],array $authThird = [])
} {
Config\Config::$options = array_merge(Config\Config::$options, $options); if (!in_array($type, Config\Config::$typeList)) {
return false;
Config\Config::$config = array_merge(Config\Config::$config, $config); } else {
Config\Config::$type = $type;
$this->AccessToken()->certificate(false); }
return $this;
} $this->options = array_merge(Config\Config::$options, $options);
$this->cacheConfig = array_merge(Config\Config::$config, $config);
static public function go()
{
if (NULL == self::$self) { // $this->AccessToken()->certificate(false);
return new \wechatkit\Run\Run();
} else { return $this;
return self::$self; }
}
} static public function go($class=null)
{
public function getAccessToken($appid){
if (NULL == self::$self) {
return $this->AccessToken()->getAccessToken($appid); $instance = new \wechatkit\Run\Run();
self::$self = $instance;
} } else {
$instance = self::$self;
}
/** if($class)
* @param array $arr self::$namespace = $class;
* @param $value else self::$namespace = null;
* @return array
*/
protected function key(array $arr, $value) return $instance;
{ }
return array_keys($arr, $value);
} public function getAccessToken($appid){
/** return $this->AccessToken()->getAccessToken($appid);
* @param $name
* @param $arguments }
* @return mixed
* @throws \Exception
*/ /**
public function __call($name, $arguments) * @param array $arr
{ * @param $value
if (is_dir(__DIR__ . DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR . $name)) { * @return array
$className = '\wechatkit\\' . $name . '\\' . $name; */
protected function key(array $arr, $value)
return new $className(); {
} else { return array_keys($arr, $value);
throw new \Exception('class ' . $name . ' not found!'); }
}
} /**
* @param $name
/* * @param $arguments
* O save * @return mixed
* */ * @throws \Exception
public function componentVerifyTicketSave($component_verify_ticket) */
{ public function __call($name = null, $arguments)
$componentDir = sprintf(Config\Config::$config['cachePath'], Config\Config::$options['open']['appid']); {
if (!is_dir($componentDir)) { $namespace = self::$namespace?:$name;
if (!mkdir($componentDir, 0777, TRUE)) {
throw new \Exception('DIR "' . $componentDir . '" no write! place create this'); if (is_dir(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $namespace)) {
} $className = '\wechatkit\\' . $namespace . '\\' . $name;
}
return new $className($this->options);
$ret = file_put_contents($componentDir . DIRECTORY_SEPARATOR . 'component_verify_ticket', $component_verify_ticket); } else {
if ($ret) { throw new \Exception('class ' . $name . ' not found!');
return TRUE; }
} }
}
/*
public function certificatesSave($wxappid,$name,$value) * O save
{ * */
$componentDir = sprintf(Config\Config::$config['cachePath'], $wxappid); public function componentVerifyTicketSave($component_verify_ticket)
if (!is_dir($componentDir)) { {
if (!mkdir($componentDir, 0777, TRUE)) { $componentDir = sprintf(Config\Config::$config['cachePath'], Config\Config::$options['open']['appid']);
throw new \Exception('DIR "' . $componentDir . '" no write! place create this'); if (!is_dir($componentDir)) {
} if (!mkdir($componentDir, 0777, TRUE)) {
} throw new \Exception('DIR "' . $componentDir . '" no write! place create this');
}
$ret = file_put_contents($componentDir . DIRECTORY_SEPARATOR . $name, $value); }
if ($ret) {
return TRUE; $ret = file_put_contents($componentDir . DIRECTORY_SEPARATOR . 'component_verify_ticket', $component_verify_ticket);
} if ($ret) {
} return TRUE;
}
}
}
\ No newline at end of file public function certificatesSave($wxappid,$name,$value)
{
$componentDir = sprintf(Config\Config::$config['cachePath'], $wxappid);
if (!is_dir($componentDir)) {
if (!mkdir($componentDir, 0777, TRUE)) {
throw new \Exception('DIR "' . $componentDir . '" no write! place create this');
}
}
$ret = file_put_contents($componentDir . DIRECTORY_SEPARATOR . $name, $value);
if ($ret) {
return TRUE;
}
}
}
...@@ -2,57 +2,62 @@ ...@@ -2,57 +2,62 @@
namespace wechatkit\Service; namespace wechatkit\Service;
use wechatkit\Config\Config;
use wechatkit\CryptMsg\CryptMsg; use wechatkit\CryptMsg\CryptMsg;
use wechatkit\Run\BaseRun;
class Service { class Service extends BaseRun {
public $postData; public $postData;
public $xml; public $xml;
public $xmlArray; public $xmlArray;
public function __construct() public function handle($postData){
{
$this->postData = file_get_contents('php://input'); $this->postData = $postData;//file_get_contents('php://input');
if(!$this->postData){ if(!$this->postData){
exit(255); return $this;
} }
$cryptmsg = new CryptMsg();
debug('=====================进入service.php'); debug('=====================执行微信消息解密流程===================');
if(Config::$type == 'A'){
$this->xml = simplexml_load_string($this->postData, 'SimpleXMLElement', LIBXML_NOCDATA); $cryptmsg = new CryptMsg();
if($this->xml->Encrypt){ if($this->authType == 'A'){
$cryptmsg->WXBizMsgCrypt(Config::$options['token'],Config::$options['encodingAesKey'], Config::$options['appid']); $this->xml = simplexml_load_string($this->postData, 'SimpleXMLElement', LIBXML_NOCDATA);
$ret = $cryptmsg->decryptMsg($_GET['msg_signature'], $_GET['timestamp'], $_GET['nonce'], $this->postData, $this->xml); if($this->xml->Encrypt){
$cryptmsg->WXBizMsgCrypt($this->options['token'],$this->options['encodingAesKey'], $this->options['appid']);
$this->xml = simplexml_load_string($this->xml, 'SimpleXMLElement', LIBXML_NOCDATA); $ret = $cryptmsg->decryptMsg($_GET['msg_signature'], $_GET['timestamp'], $_GET['nonce'], $this->postData, $this->xml);
} $this->xml = simplexml_load_string($this->xml, 'SimpleXMLElement', LIBXML_NOCDATA);
$this->xmlArray = json_decode(json_encode($this->xml),1); }
}elseif(Config::$type == 'O'){ $this->xmlArray = json_decode(json_encode($this->xml),1);
$cryptmsg->WXBizMsgCrypt(Config::$options['open']['token'],Config::$options['open']['encodingAesKey'], Config::$options['open']['appid']); }elseif($this->authType == 'O'){
$result = $cryptmsg->decryptMsg($_GET['msg_signature'], $_GET['timestamp'], $_GET['nonce'], $this->postData, $this->xml); $cryptmsg->WXBizMsgCrypt($this->options['open']['token'],$this->options['open']['encodingAesKey'], $this->options['open']['appid']);
if(0 != $result){ $result = $cryptmsg->decryptMsg($_GET['msg_signature'], $_GET['timestamp'], $_GET['nonce'], $this->postData, $this->xml);
#解密失败 if(0 != $result){
if(function_exists('debug')){ #解密失败
debug('微信数据解密失败'.$result); if(function_exists('debug')){
} debug('微信数据解密失败'.$result);
}else{ }
debug('=====================进入service.php'); }else{
$this->xml = simplexml_load_string($this->xml, 'SimpleXMLElement', LIBXML_NOCDATA); $this->xml = simplexml_load_string($this->xml, 'SimpleXMLElement', LIBXML_NOCDATA);
$this->xmlArray = json_decode(json_encode($this->xml),1); $this->xmlArray = json_decode(json_encode($this->xml),1);
}
}else{ debug("===========微信信息解密成功==========".PHP_EOL.json_encode($this->xmlArray));
$this->xml = simplexml_load_string($this->postData, 'SimpleXMLElement', LIBXML_NOCDATA); }
$xmlArray = $this->xmlArray = json_decode(json_encode($this->xml),1); }else{
debug('================$xml'.$xml.'------------$xmlArray'.$xmlArray); $this->xml = simplexml_load_string($this->postData, 'SimpleXMLElement', LIBXML_NOCDATA);
} $this->xmlArray = json_decode(json_encode($this->xml),1);
}
}
return $this;
}
public function run(){ public function decryptData(){
return $this->xml; return $this->xml;
} }
public function runArray(){ public function decryptArray(){
return $this->xmlArray; return $this->xmlArray;
} }
......
File mode changed
File mode changed
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!