public function receivewechat($appid)
{
if (ob_get_level() == 0) ob_start();
ob_implicit_flush(true);
ob_clean();
header("Content-type:text/xml charset=\"utf-8\"");
#log_msg(headers_list());
$request = Request::instance();
$signature = $request->param("signature");
$msg_sign = $request->param("msg_signature");
// 时间戳
$timestamp = $request->param("timestamp");
// 随机数
$nonce = $request->param("nonce");
$encrypt_type = $request->param("encrypt_type");
$pc = new \WXBizMsgCrypt(config('authorizer.token'), config('authorizer.encodingAesKey'), config('authorizer.component_appid'));
$encryptMsg = file_get_contents('php://input');
$errCode = $pc->decryptMsg($signature, $timestamp, $nonce, $encryptMsg, $msg);
if ($errCode == 0) {
$authorization_code = Db::name('authorization_code')->where('authorizer_id', $applet['id'])->find();
$de_xml_tree = new \DOMDocument();
$de_xml_tree->loadXML($msg);
$array_m = $de_xml_tree->getElementsByTagName('MsgType');
if(isset($array_m->item(0)->nodeValue)){
$event_m = $array_m->item(0)->nodeValue;
switch ($event_m) {
case "event":
$array_i = $de_xml_tree->getElementsByTagName('Event');
$event = $array_i->item(0)->nodeValue;
switch ($event) {
case 'user_enter_tempsession':
error_log("user_enter_tempsession\n", 3, '/tmp/xgtf_ltt');
echo "success";
$FromUserName_i = $de_xml_tree->getElementsByTagName('FromUserName');
$str = '{
"touser":"'.$FromUserName_i->item(0)->nodeValue.'",
"msgtype":"text",
"text":
{
"content":"欢迎光临"
}
}';
$access_token = get_authorizer_access_token($appid);
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$access_token}" );
curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
curl_setopt ( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)' );
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt ( $ch, CURLOPT_AUTOREFERER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $str );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
$tmpInfo = curl_exec ( $ch );
break;
}
break;
case "text":
$FromUserName_i = $de_xml_tree->getElementsByTagName('FromUserName');
$ToUserName_i = $de_xml_tree->getElementsByTagName('ToUserName');
$textTpl = "
%s";
$textTpl = sprintf ($textTpl,$FromUserName_i->item(0)->nodeValue, $ToUserName_i->item(0)->nodeValue, time());
$encryptMsg_now = '';
$return_errCode = $pc->encryptMsg($textTpl, $timestamp, $nonce, $encryptMsg_now);
return $encryptMsg_now;
}
}
} else {
trace($errCode . "\n");
error_log($errCode . "\n", 3, '/tmp/xgtf_error');
}
}
欢迎光临自动回复已成功,但是发送的消息无法转发到网页客服系统工具中,请问为什么
微信小程序开发问题解答
微信小程序开发者回答:
没看到代码中有配置客服转接https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/customer-message/trans.html
本文网址:http://www.91bianli.com/weixinxiaochengxu/40149.html