客服消息后台设置后,无响应的问题
发布于 6 年前 作者 juan20 18738 次浏览 来自 问答

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

前端是用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;   }

3 回复

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;

    }

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

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

回到顶部