小程序
小游戏
企业微信
微信支付
扫描小程序码分享
递交全网发布的时候 授权URL能收到2条 一条授权 一条取消授权
普通消息URL收不到 https://paitume.com/api/wx/notify_msg/$APPID$
第三方服务APPID:wxbba5163d50a0ff41
测试号已经加入到白名单:授权测试公众号列表:gh_3c884a361561 但是经常修改后再修改就没有了??
是不是这个原因导致没有消息
和代码无关 Nginx的日志并没有微信的记录 授权的正常
谢谢工作人员~
7 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
public function notify_msg($fromAppId){
CLogger::info('微信消息1',$_GET);
CLogger::info('微信消息2'.file_get_contents("php://input") );
$timeStamp = $this->input->get_post('timestamp');
$nonce = $this->input->get_post('nonce');
$msg_sign = $this->input->get_post('msg_signature');
$encryptMsg = file_get_contents('php://input');
if(!$encryptMsg){
CLogger::error('notify_msg没有input');
echo 'error'; exit();
}
$token = 'paitume';
$encodingAesKey = '后台定义的解密字符串43位';
$myAppId = '自己的第三方appid';
//解密消息
$pc = new WxBizMsgCrypt($token, $encodingAesKey, $myAppId);
$xml_tree = new DOMDocument();
$xml_tree->loadXML($encryptMsg);
$array_e = $xml_tree->getElementsByTagName('Encrypt');
$encrypt = $array_e->item(0)->nodeValue;
//替换百分号
$format = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%s]]></Encrypt></xml>";
$from_xml = sprintf($format, $encrypt);
// 解密
$msg = '';
$errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $from_xml, $msg);
if ($errCode == 0) {
CLogger::info('解密成功',[$msg]);
$xml = new DOMDocument();
$xml->loadXML($msg);
$array_content = $xml->getElementsByTagName('Content');
$array_user = $xml->getElementsByTagName('FromUserName');
$fromUserOpenId = $array_user->item(0)->nodeValue;
$content = $array_content->item(0)->nodeValue;
if($content == 'TESTCOMPONENT_MSG_TYPE_TEXT'){
CLogger::info('发送TESTCOMPONENT_MSG_TYPE_TEXT_callback');
$time = time();
header("Content-type:text/xml");
$xml = new \SimpleXMLElement('<xml></xml>');
$sendData['ToUserName'] = $fromUserOpenId;
$sendData['FromUserName'] ='gh_xxxxxxx';//你的原始appID
$sendData['CreateTime'] = $time;
$sendData['MsgType'] = 'text';
$sendData['Content'] = 'TESTCOMPONENT_MSG_TYPE_TEXT_callback';
$this->_data2xml($xml, $sendData);
$str = $xml->asXML();
$sEncryptMsg = ""; //xml格式的密文
$errCode = $pc->encryptMsg($str, $time, $nonce, $sEncryptMsg);
CLogger::info('加密消息'.$errCode.'---'.$sEncryptMsg);
echo $sEncryptMsg;
exit();
} else if(strpos($content,'QUERY_AUTH_CODE') !== false){
CLogger::info('消息包含QUERY_AUTH_CODE'.$content);
echo "";
$queryAuthCode = str_replace('QUERY_AUTH_CODE:','',$content);
$componentAccessToken = $this->getComponentAccessToken();
$url = 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token='.$componentAccessToken;
$authDataArray['component_appid'] = $myAppId;
$authDataArray['authorization_code'] = $queryAuthCode;
$authResult = $this->curl_post($url, json_encode($authDataArray));
CLogger::info('授权Auth返回',$authResult);
$authorizationInfo = $authResult['authorization_info'];
$authorizerAccessToken = $authorizationInfo['authorizer_access_token'];
if($authorizerAccessToken){
$sendMsgUrl = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$authorizerAccessToken;
$msgData['access_token'] = $authorizerAccessToken;
$msgData['touser'] = $fromUserOpenId;
$msgData['msgtype'] = 'text';
$msgData['text'] = ['content'=>$queryAuthCode.'_from_api'];
$sendMsgResult = $this->curl_post($sendMsgUrl, json_encode($msgData));
CLogger::info('发送客服消息返回'.json_encode($sendMsgResult));
} else {
CLogger::error('消息解密失败');
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
你好 在吗 同问
你好,请使用 tcpdump 来监控上下行消息, 开发这边确定是服务器回包不正确导致的。
同问,等一波回复
在线等
我也遇到这样问题。。
关注该问题。
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
public function notify_msg($fromAppId){
CLogger::info('微信消息1',$_GET);
CLogger::info('微信消息2'.file_get_contents("php://input") );
$timeStamp = $this->input->get_post('timestamp');
$nonce = $this->input->get_post('nonce');
$msg_sign = $this->input->get_post('msg_signature');
$encryptMsg = file_get_contents('php://input');
if(!$encryptMsg){
CLogger::error('notify_msg没有input');
echo 'error'; exit();
}
$token = 'paitume';
$encodingAesKey = '后台定义的解密字符串43位';
$myAppId = '自己的第三方appid';
//解密消息
$pc = new WxBizMsgCrypt($token, $encodingAesKey, $myAppId);
$xml_tree = new DOMDocument();
$xml_tree->loadXML($encryptMsg);
$array_e = $xml_tree->getElementsByTagName('Encrypt');
$encrypt = $array_e->item(0)->nodeValue;
//替换百分号
$format = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%s]]></Encrypt></xml>";
$from_xml = sprintf($format, $encrypt);
// 解密
$msg = '';
$errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $from_xml, $msg);
if ($errCode == 0) {
CLogger::info('解密成功',[$msg]);
$xml = new DOMDocument();
$xml->loadXML($msg);
$array_content = $xml->getElementsByTagName('Content');
$array_user = $xml->getElementsByTagName('FromUserName');
$fromUserOpenId = $array_user->item(0)->nodeValue;
$content = $array_content->item(0)->nodeValue;
if($content == 'TESTCOMPONENT_MSG_TYPE_TEXT'){
CLogger::info('发送TESTCOMPONENT_MSG_TYPE_TEXT_callback');
$time = time();
header("Content-type:text/xml");
$xml = new \SimpleXMLElement('<xml></xml>');
$sendData['ToUserName'] = $fromUserOpenId;
$sendData['FromUserName'] ='gh_xxxxxxx';//你的原始appID
$sendData['CreateTime'] = $time;
$sendData['MsgType'] = 'text';
$sendData['Content'] = 'TESTCOMPONENT_MSG_TYPE_TEXT_callback';
$this->_data2xml($xml, $sendData);
$str = $xml->asXML();
$sEncryptMsg = ""; //xml格式的密文
$errCode = $pc->encryptMsg($str, $time, $nonce, $sEncryptMsg);
CLogger::info('加密消息'.$errCode.'---'.$sEncryptMsg);
echo $sEncryptMsg;
exit();
} else if(strpos($content,'QUERY_AUTH_CODE') !== false){
CLogger::info('消息包含QUERY_AUTH_CODE'.$content);
echo "";
$queryAuthCode = str_replace('QUERY_AUTH_CODE:','',$content);
$componentAccessToken = $this->getComponentAccessToken();
$url = 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token='.$componentAccessToken;
$authDataArray['component_appid'] = $myAppId;
$authDataArray['authorization_code'] = $queryAuthCode;
$authResult = $this->curl_post($url, json_encode($authDataArray));
CLogger::info('授权Auth返回',$authResult);
$authorizationInfo = $authResult['authorization_info'];
$authorizerAccessToken = $authorizationInfo['authorizer_access_token'];
if($authorizerAccessToken){
$sendMsgUrl = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$authorizerAccessToken;
$msgData['access_token'] = $authorizerAccessToken;
$msgData['touser'] = $fromUserOpenId;
$msgData['msgtype'] = 'text';
$msgData['text'] = ['content'=>$queryAuthCode.'_from_api'];
$sendMsgResult = $this->curl_post($sendMsgUrl, json_encode($msgData));
CLogger::info('发送客服消息返回'.json_encode($sendMsgResult));
}
}
} else {
CLogger::error('消息解密失败');
}
}
你好 在吗 同问
你好,请使用 tcpdump 来监控上下行消息, 开发这边确定是服务器回包不正确导致的。
同问,等一波回复
在线等
我也遇到这样问题。。
关注该问题。