收藏
回答

客服消息后台设置后,无响应的问题

问题模块
API和组件



以下是我的代码设置,请问是哪里出错了?进入客服会话后,输入信息没有响应。

前端是用button进入客服会话

<button class="products-submit" open-type="contact" session-from="weapp"            bindcontact="submit_contact">立即提交button>

后台方面,在小程序中已经开通了消息推送。上传服务器的代码设置如下:

$wechatObj->responseMsg();

响应设置的方法

public function responseMsg()

  {

//get post data, May be due to the different environments

GLOBALS["HTTP_RAW_POST_DATA"];

    //extract post data

if (!empty($postStr)){

              libxml_disable_entity_loader(true);

            $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);

              $openid = trim($postObj->FromUserName);

              $toUsername = trim($postObj->ToUserName);

              $content = trim($postObj->Content);

              $appId = "";

              $secret = "";//appid和secret保密

              $getTokenapi = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appId}&secret={$secret}";

              this->httpGet($getTokenapi);

              $arr = json_decode($resultStr,true);

              $token = arr["access_token"];

              $postMsgApi = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$token}";

              $data = array("touser"=>$openid,"msgtype"=>"text","text"=>array("content"=>"你好,欢迎交流!"));

              $json = json_encode($data);

              this->httpPost(json);

              echo $str;

      }else {

      echo "";

      exit;       }

  }

http请求的方法:

public function httpPost(jsonStr){  

    $ch = curl_init();  

    curl_setopt($ch, CURLOPT_POST, 1);  

    curl_setopt(url);  

    curl_setopt(jsonStr);  

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(  

        'Content-Type: application/json; charset=utf-8',  

        'Content-Length: ' . strlen($jsonStr)  

      )       );  

    $response = curl_exec($ch);  

    if(curl_errno($ch)){

      return curl_error($ch);     }

    curl_close($ch);

    return $response;   }  

  public function httpGet($url){

      $curl = curl_init();

      curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);

      curl_setopt($curl, CURLOPT_TIMEOUT,500);

      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,true);

      curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,true);

      curl_setopt($curl, CURLOPT_URL,$url);

        $res = curl_exec($curl);

        curl_close(($curl));

        return $res;   }


最后一次编辑于  2017-12-04  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏投诉关注问题回答

3 个回答

  • Ron
    Ron
    2017-12-04

    httpget方法发表后总是变得跟发表前写的不一样

    public function httpGet($url){

            $curl = curl_init();

            curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);

            curl_setopt($curl, CURLOPT_TIMEOUT,500);

            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,true);

            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,true);

            curl_setopt($curl, CURLOPT_URL,$url);

            $res = curl_exec($curl);

            curl_close(($curl));

            return $res;

        }


    2017-12-04
    赞同
    回复
  • 郑俊伟
    郑俊伟
    2017-12-04

    服务器是否收到消息请求了?如果收到请求且正常,调用api接口下发时,请求的参数和结果分别是什么?

    2017-12-04
    赞同
    回复
  • Ron
    Ron
    2017-12-04

    怎么查看服务器上是否收到消息。我是新手,求帮忙!

    2017-12-04
    赞同
    回复