public function responseMsg()
{
global $_W,$_GPC;
$fromUsername = $_GPC['__input']['FromUserName'];
$toUserName = $_GPC['__input']['ToUserName'];
if($_GPC['__input']['MsgType'] == 'event' && $_GPC['__input']['Event']=='user_enter_tempsession'){
$content = '您好,有什么能帮助你?';
$data=array(
"touser"=>$fromUsername,
"msgtype"=>"text",
"text"=>array("content"=>$content)
);
$json = json_encode($data,JSON_UNESCAPED_UNICODE);
$this->requestAPI($json);
}elseif(!empty($_GPC['__input']['MsgType']) && $_GPC['__input']['MsgType'] == 'text'){
file_put_contents(IA_ROOT.'/123.txt',print_r($_GPC,true));
$data=array(
"ToUserName"=>$toUserName,
"FromUserName"=>$fromUsername,
"CreateTime"=>time(),
"MsgType"=>"text",
'Content' => $_GPC['__input']['Content'],
"MsgId" => $_GPC['__input']['MsgId'],
);
$json = json_encode($data,JSON_UNESCAPED_UNICODE);
$this->requestAPI($json);
}elseif(!empty($postArr['MsgType']) && $postArr['MsgType'] == 'image'){
$data = array(
"ToUserName"=>$toUserName,
"FromUserName"=>$fromUsername,
"Content" => $_GPC['__input']['Content'],
"CreateTime"=>time(),
"MsgType"=>"transfer_customer_service",
"MsgId" => $_GPC['__input']['MsgId'],
);
$json = json_encode($data,JSON_UNESCAPED_UNICODE);
$this->requestAPI($json);
}
}
public function requestAPI($json){
$access_token = $this->get_accessToken();
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$access_token;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($json)){
curl_setopt($curl, CURLOPT_POSTFIELDS,$json);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
file_put_contents(IA_ROOT.'/1234.txt',print_r($output,true));
if (curl_errno($curl)) {
echo 'Errno'.curl_error($curl);
}
curl_close($curl);
if($output == 0){
echo 'success';exit;
}
}
|
确定json格式是否正确,openid 是否正确 access-token是否正确。
刚才测试了一下,用户发送消息,我拿到了,然后按格式填好转json格式,然后再发出去,难道是我发送的地址有错了。。?
救救孩子吧。。。
{"errcode":40003,"errmsg":"invalid openid hint: [rIlKqA00705508]"}一直在报这个问题