小程序
小游戏
企业微信
微信支付
扫描小程序码分享
1、我用PHP生成了微信客服账号链接,如下:
https://work.weixin.qq.com/kfid/kfcb8812df7efcfd709?enc_scene=ENC3NX3fazgsBa8J3ybGyiv7qj9y5miKguXgn7TMZtqyjkWD7qvhByZfpPDcL3VSRtLMV&scene_param=202405270534308645890
访问这个链接可以打开客服会话窗口,但为什么没有触发任何事件呢?
2、自创建的应用,并且已经设置接收消息事件的服务器配置,也允许应用调用API接口,如下图:
3、给客服账号发送消息,后端是可以接收到信息的,就是打开链接时,没有触发“用户进入会话事件”
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
你好,请移步企微官方讨论区:https://developer.work.weixin.qq.com/community/question
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
贴一下PHP后端相关代码:
<?php namespace app\index\controller; use think\Controller; use think\Request; use weixinwork\WXBizMsgCrypt; /** * 微信接口类 */ class Weixin extends Common{ public function _initialize(){ parent::_initialize(); } /** * 企业微信客服:接收消息和事件 */ public function msg(){ //1.验证URL //$this->verifyURL($_GET);exit; //2.接收用户发送的消息 $xmldata=file_get_contents("php://input"); $this->receiveMsg($_GET,$xmldata); } /** * 企业微信客服:验证链接 */ public function verifyURL($data){ $token = config("weixin.token"); $encodingAesKey = config("weixin.encodingAesKey"); $corpId = config("weixin.corpid"); //接收GET参数 $sReqMsgSig = $data['msg_signature']; $sReqTimeStamp = $data['timestamp']; $sReqNonce = $data['nonce']; $sVerifyEchoStr = $data['echostr']; $sEchoStr = ""; $wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId); $errCode = $wxcpt->VerifyURL($sReqMsgSig, $sReqTimeStamp, $sReqNonce, $sVerifyEchoStr, $sEchoStr); if ($errCode == 0) { //原样返回明文消息内容 echo $sEchoStr; } } /** * 企业微信客服:接收消息 */ public function receiveMsg($data,$xmldata){ $token = config("weixin.token"); $encodingAesKey = config("weixin.encodingAesKey"); $corpId = config("weixin.corpid"); //接收GET参数 $sReqMsgSig = $data['msg_signature']; $sReqTimeStamp = $data['timestamp']; $sReqNonce = $data['nonce']; try { $sMsg = ''; //解密后的明文内容 $wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId); //检验消息的真实性,并且获取解密后的明文 $errCode = $wxcpt->DecryptMsg($sReqMsgSig, $sReqTimeStamp, $sReqNonce, $xmldata,$sMsg); if ($errCode == 0 && !empty($sMsg)) { $xml = simplexml_load_string($sMsg, 'SimpleXMLElement', LIBXML_NOCDATA); $array = json_encode($xml); $array = json_decode($array,true); //读取消息内容 $Token = $array["Token"]; $OpenKfId = $array["OpenKfId"]; $result = WeixinBiz::getInstance()->readMsg($Token,$OpenKfId); printLog("读取到的消息内容:".json_encode($result,JSON_UNESCAPED_UNICODE)); }else{ printLog("接收消息失败,错误码: " . $errCode); } } catch (Exception $e) { printLog("接收消息异常,Error: " . $e); } }
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
你好,请移步企微官方讨论区:https://developer.work.weixin.qq.com/community/question
贴一下PHP后端相关代码:
<?php namespace app\index\controller; use think\Controller; use think\Request; use weixinwork\WXBizMsgCrypt; /** * 微信接口类 */ class Weixin extends Common{ public function _initialize(){ parent::_initialize(); } /** * 企业微信客服:接收消息和事件 */ public function msg(){ //1.验证URL //$this->verifyURL($_GET);exit; //2.接收用户发送的消息 $xmldata=file_get_contents("php://input"); $this->receiveMsg($_GET,$xmldata); } /** * 企业微信客服:验证链接 */ public function verifyURL($data){ $token = config("weixin.token"); $encodingAesKey = config("weixin.encodingAesKey"); $corpId = config("weixin.corpid"); //接收GET参数 $sReqMsgSig = $data['msg_signature']; $sReqTimeStamp = $data['timestamp']; $sReqNonce = $data['nonce']; $sVerifyEchoStr = $data['echostr']; $sEchoStr = ""; $wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId); $errCode = $wxcpt->VerifyURL($sReqMsgSig, $sReqTimeStamp, $sReqNonce, $sVerifyEchoStr, $sEchoStr); if ($errCode == 0) { //原样返回明文消息内容 echo $sEchoStr; } } /** * 企业微信客服:接收消息 */ public function receiveMsg($data,$xmldata){ $token = config("weixin.token"); $encodingAesKey = config("weixin.encodingAesKey"); $corpId = config("weixin.corpid"); //接收GET参数 $sReqMsgSig = $data['msg_signature']; $sReqTimeStamp = $data['timestamp']; $sReqNonce = $data['nonce']; try { $sMsg = ''; //解密后的明文内容 $wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId); //检验消息的真实性,并且获取解密后的明文 $errCode = $wxcpt->DecryptMsg($sReqMsgSig, $sReqTimeStamp, $sReqNonce, $xmldata,$sMsg); if ($errCode == 0 && !empty($sMsg)) { $xml = simplexml_load_string($sMsg, 'SimpleXMLElement', LIBXML_NOCDATA); $array = json_encode($xml); $array = json_decode($array,true); //读取消息内容 $Token = $array["Token"]; $OpenKfId = $array["OpenKfId"]; $result = WeixinBiz::getInstance()->readMsg($Token,$OpenKfId); printLog("读取到的消息内容:".json_encode($result,JSON_UNESCAPED_UNICODE)); }else{ printLog("接收消息失败,错误码: " . $errCode); } } catch (Exception $e) { printLog("接收消息异常,Error: " . $e); } }