easywechat 6 怎么实现消息解密

aspire

easywechat 6 怎么实现消息解密

文档地址:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/Message_encryption_and_decryption.html

已经收到了消息,但是不知道怎么解密,官方demo是php7.2,有些函数不支持,换了就不能解密,下面是我收到消息的代码

$symfony_request = new SymfonyRequest($request->get(), $request->post(), [], $request->cookie(), [], [], $request->rawBody());
$symfony_request->headers = new HeaderBag($request->header());
$this->app->setRequestFromSymfonyRequest($symfony_request);
$server = $this->app->getServer();
$data = $server->getDecryptedMessage();
var_dump($data->Encrypt,$data->toArray()); //这个怎么解密
$response = $server->serve();
return $response->getBody();

加密消息:

string(684) "AX32OVMIozfuT7b7DJ5hLvjhGbAvZ1IHjJ6lfHuESQ2VeukZ04zFwkON5a00lf4FQ1rNTTfSXpoEvWTs8YY9LKyOypWrrB1mjppSIQ9tU6P13xatJgqMLEwBDNL0gSeRe7tdPsoJI+MIj4bUvY9/01PPoxk98MCiHHJfI6e2t/4VxFBIlcj3WhiN1NnqBuU9ahdCJeVOwcqETSAvoQ7Y7QCg3VRFSh7mVBFbAk456WM190eMBAjsJx+frvqfxv21jvFkVKKUr4/yt++v0+6fbeRKqhnekbBzb5lB18SDxTtkp4ZbtfTsmO/XYH8mj+HN5glAajdFTVvhGXyLFEOAvwgCZyL6frEsbKnhr5x1i2Y6G6OdK0T6L/cT7tpE75NrixmowE7mrs66FolSJqNAUdPcDmgoBifG7HUCt17ljBL47CTltYyeO4O/sh1xXksABLEJLKOTc9FAmk+FBwVwjlUx/HzxKDhxzoCrVWjt372PE1M737yriLVQ0RJtGssOZNvVMzywaXio20BKJdPqcHO44QG3GYU/u6aAIo/ofFOXJk13O8zNFThFDGQulAOJ2Rx7FTHu7qa3lAN4gDV+qElQcRazTPPKT3zWNS4rmxigpdRx4MSY7MebvNg57gMcpfJSRb9mV6H87vcCnAdOimQkjdACq++jAAe2I/rOkF8="
array(2) {
  ["ToUserName"]=>
  string(15) "gh_65bf8a9bc75a"
  ["Encrypt"]=>
  string(684) "AX32OVMIozfuT7b7DJ5hLvjhGbAvZ1IHjJ6lfHuESQ2VeukZ04zFwkON5a00lf4FQ1rNTTfSXpoEvWTs8YY9LKyOypWrrB1mjppSIQ9tU6P13xatJgqMLEwBDNL0gSeRe7tdPsoJI+MIj4bUvY9/01PPoxk98MCiHHJfI6e2t/4VxFBIlcj3WhiN1NnqBuU9ahdCJeVOwcqETSAvoQ7Y7QCg3VRFSh7mVBFbAk456WM190eMBAjsJx+frvqfxv21jvFkVKKUr4/yt++v0+6fbeRKqhnekbBzb5lB18SDxTtkp4ZbtfTsmO/XYH8mj+HN5glAajdFTVvhGXyLFEOAvwgCZyL6frEsbKnhr5x1i2Y6G6OdK0T6L/cT7tpE75NrixmowE7mrs66FolSJqNAUdPcDmgoBifG7HUCt17ljBL47CTltYyeO4O/sh1xXksABLEJLKOTc9FAmk+FBwVwjlUx/HzxKDhxzoCrVWjt372PE1M737yriLVQ0RJtGssOZNvVMzywaXio20BKJdPqcHO44QG3GYU/u6aAIo/ofFOXJk13O8zNFThFDGQulAOJ2Rx7FTHu7qa3lAN4gDV+qElQcRazTPPKT3zWNS4rmxigpdRx4MSY7MebvNg57gMcpfJSRb9mV6H87vcCnAdOimQkjdACq++jAAe2I/rOkF8="
}

折磨了很久,哪位好心大佬帮帮我。。。😔😔😔

831 1 0
1个回答

yzh52521

// 推送消息,已解密

$message = $server->getReqeustMessage();
  • aspire 2023-09-26
    $symfony_request = new SymfonyRequest($request->get(), $request->post(), [], $request->cookie(), [], [], $request->rawBody());
    $symfony_request->headers = new HeaderBag($request->header());
    $this->app->setRequestFromSymfonyRequest($symfony_request);
    $server = $this->app->getServer();
    $data = $server->getDecryptedMessage();
    $message = $server->getRequestMessage();
    var_dump($data->Encrypt,$data->toArray(),$message); //这个怎么解密
    $response = $server->serve();
    return $response->getBody();

    返回:

    string(684) "YfzBgLbcLM6PgqsUnoakK3Lh7YACtnzJYgrWOYWVxrD3TGyazLKyQ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wB8MCC8PNOq+fKzni783GTiXb2FVVUMwuA8rbaHgstOczajys/GSyOi1o0IXbRacTBBWK/TGkCIcwg/0R/2T/Z9ytRTmqn4apG8UdrIMgfW2aidCrg9yDl2l/7YkI0V9TjKN7nrI3nsmS5/UPcrOhq7XIq6NNCdU5bMeIZWD1sjFyqJ8FAh8Fvu6oiecPVT9j9F1xFiBsuEdq/yjC9JNJeAa3U+hKoLxMoeZ/vp27b5FdGep9eOhKMlJUdgUpJmAeDXAN8HbblAr4Xig6SVLj9PEk7eQxQVHs4WCkTDhwOCQtrfR4uxHvLzQ="
    }
    object(EasyWeChat\OfficialAccount\Message)#171 (2) {
      ["originContent":protected]=>
      string(729) "{"ToUserName":"gh_65bf8a9bc75a","Encrypt":"YfzBgLbcLM6PgqsUnoakK3Lh7YACtnzJYgrWOYWVxrD3TGyazLKyQMRP9SMCfg4U/EHF7JONLUqA0rZIK0lvhhdAzHL2keON/P3u7g3qImLvEaSYVlZX2Lo5YOT5twttrVdmTRkv+59XBtTYdFRcGpiB1DqIj/VfqotdvtjPPRkUXVSSRN87RCw6qmwZpazqX9x3pa0tF/Lu6AgfVm8fvlZLCpdr1FJPpgqjKP7A3npQzV+mg5HPHDJ9xVVsXj7phr+atu+cgqreze3yBKr7NQ+GFdJuwoRz2fwcxktcZhDfQdMeZC9shQTMgiDWPbQT5M4dIZmLs2P57tzZZFzDnF9YSuJC+n/t1BsGd+GWZxx/EQt5NDFwB8MCC8PNOq+fKzni783GTiXb2FVVUMwuA8rbaHgstOczajys/GSyOi1o0IXbRacTBBWK/TGkCIcwg/0R/2T/Z9ytRTmqn4apG8UdrIMgfW2aidCrg9yDl2l/7YkI0V9TjKN7nrI3nsmS5/UPcrOhq7XIq6NNCdU5bMeIZWD1sjFyqJ8FAh8Fvu6oiecPVT9j9F1xFiBsuEdq/yjC9JNJeAa3U+hKoLxMoeZ/vp27b5FdGep9eOhKMlJUdgUpJmAeDXAN8HbblAr4Xig6SVLj9PEk7eQxQVHs4WCkTDhwOCQtrfR4uxHvLzQ="}"
      ["attributes":protected]=>
      array(2) {
        ["ToUserName"]=>
        string(15) "gh_65bf8a9bc75a"
        ["Encrypt"]=>
        string(684) "YfzBgLbcLM6PgqsUnoakK3Lh7YACtnzJYgrWOYWVxrD3TGyazLKyQMRP9SMCfg4U/EHF7JONLUqA0rZIK0lvhhdAzHL2keON/P3u7g3qImLvEaSYVlZX2Lo5YOT5twttrVdmTRkv+59XBtTYdFRcGpiB1DqIj/VfqotdvtjPPRkUXVSSRN87RCw6qmwZpazqX9x3pa0tF/Lu6AgfVm8fvlZLCpdr1FJPpgqjKP7A3npQzV+mg5HPHDJ9xVVsXj7phr+atu+cgqreze3yBKr7NQ+GFdJuwoRz2fwcxktcZhDfQdMeZC9shQTMgiDWPbQT5M4dIZmLs2P57tzZZFzDnF9YSuJC+n/t1BsGd+GWZxx/EQt5NDFwB8MCC8PNOq+fKzni783GTiXb2FVVUMwuA8rbaHgstOczajys/GSyOi1o0IXbRacTBBWK/TGkCIcwg/0R/2T/Z9ytRTmqn4apG8UdrIMgfW2aidCrg9yDl2l/7YkI0V9TjKN7nrI3nsmS5/UPcrOhq7XIq6NNCdU5bMeIZWD1sjFyqJ8FAh8Fvu6oiecPVT9j9F1xFiBsuEdq/yjC9JNJeAa3U+hKoLxMoeZ/vp27b5FdGep9eOhKMlJUdgUpJmAeDXAN8HbblAr4Xig6SVLj9PEk7eQxQVHs4WCkTDhwOCQtrfR4uxHvLzQ="
      }
    }

    😭😭😭😭😭怎么办呀

  • yzh52521 2023-09-26

    $message = $server->getDecryptedMessage(); 这个就是解密后的消息啊 6.5.0+

  • aspire 2023-09-26

    我这个是虚拟支付的推送,可能他们这个消息没办法解密。。。😶

年代过于久远,无法发表回答
×
🔝