Skip to content

Commit

Permalink
feat:xml加密&增加测试
Browse files Browse the repository at this point in the history
  • Loading branch information
parieses committed Jan 10, 2024
1 parent 2cca2d1 commit e7982f3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@

require __DIR__ . '/vendor/autoload.php';


function generate($ToUserName, $FromUserName, $Content, $MsgType = 'text')
{
$format = "<xml><ToUserName><![CDATA[%s]]></ToUserName><FromUserName><![CDATA[%s]]></FromUserName><CreateTime>%s</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[%s]]></Content></xml>";
return sprintf($format, $ToUserName, $FromUserName, time(), $Content);
}
$componentAppId = 'wx108c9cc5a36ef1b0';
$componentAppSecret = '10cbbc0b28fa9dee578b8bf0f2696e48';
//消息校验Token
$token = 'henanwaifu';
//消息加解密Key
$encodingAesKey = '1CD37E73D5D74B439A167DE3014FD882521XINGFULI';
$xml = generate('admin', 'admin', 'hello world');
$weChat = new WeChatServer(Authorization::class, ['componentAppId' => $componentAppId, 'componentAppSecret' => $componentAppSecret, 'token' => $token, 'encodingAesKey' => $encodingAesKey]);
//$data = ['ticket' => 'znki2rGXe30AWTWliIrpKBVxUNf-TOQQ-54RQrXqdCULxUOtlxksDlk0batVSuzL75xvz-cbpOnKPK1tlXsqqw'];
//var_dump($weChat->exec('getComponentAccessToken',$data));
//获取要操作的类
//$object = $weChat->getInstance();
$object = $weChat->getInstance();
var_dump($object->encryptMsg($xml,time(),'123132'));die();
//$apiStartPushTicket = $object->apiStartPushTicket();
//通过ticket 获取 获取令牌
//$token = $object->apiComponentToken($data['ticket']);
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"ext-simplexml": "*",
"guzzlehttp/guzzle": "^7.4",
"wechatpay/wechatpay": "^1.4",
"ext-curl": "*"
"ext-curl": "*",
"ext-mcrypt": "*"
},
"repositories": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/library/Authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ private function getDecryptMsg($msg_signature, $timestamp, $nonce, $encryptMsg)
$errCode = $pc->decryptMsg($msg_signature, $timestamp, $nonce, $from_xml, $message);
return $errCode == 0 ? $message : false;
}
private function encryptMsg($msg_signature, $timestamp, $nonce)
public function encryptMsg($msg_signature, $timestamp, $nonce)
{
$pc = new wxBizMsgCrypt($this->token, $this->encodingAesKey, $this->componentAppId);
$message = '';
Expand Down

0 comments on commit e7982f3

Please sign in to comment.