收藏
回答

用户向客服发送消息,客服网页版收不到?

public function responseMsg()
    {
        global $_W,$_GPC;
//        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
        //$postArr = json_decode($postStr,true);
        $fromUsername = $_GPC['__input']['FromUserName'];   //发送者openid
 
        $toUserName = $_GPC['__input']['ToUserName'];       //小程序id
 
        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);  //php5.4+
            $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);  //php5.4+
            $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);  //php5.4+
            $this->requestAPI($json);
        }
    }
    public function requestAPI($json){
        $access_token = $this->get_accessToken();
 
        /*
         * POST发送https请求客服接口api
         */
        $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$access_token;
        //以'json'格式发送post的https请求
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
        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);
        //curl_setopt($curl, CURLOPT_HTTPHEADER, $headers );
        $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;
        }
    }


回答关注问题邀请回答
收藏

2 个回答

  • 少年啦
    少年啦
    2019-08-03

    确定json格式是否正确,openid 是否正确 access-token是否正确。

    2019-08-03
    有用
    回复 3
    • hjxssl
      hjxssl
      2019-08-03


      刚才测试了一下,用户发送消息,我拿到了,然后按格式填好转json格式,然后再发出去,难道是我发送的地址有错了。。?

      2019-08-03
      回复
    • hjxssl
      hjxssl
      2019-08-03

      救救孩子吧。。。

      2019-08-03
      回复
    • 少年啦
      少年啦
      2019-08-03回复hjxssl
      你通过https://mp.weixin.qq.com/debug/这个页面测试一下吧
      2019-08-03
      回复
  • hjxssl
    hjxssl
    2019-08-03
    {"errcode":40003,"errmsg":"invalid openid hint: [rIlKqA00705508]"}


    一直在报这个问题

    2019-08-03
    有用
    回复
登录 后发表内容