微信小程序調用客服php接口實現回覆消息

  <?php
    #global $wpdb, $ft_tables;
    #$token = '123';//微信-客服消息TOKEN(令牌)
    #
    #$signature = $_GET["signature"];
    #$timestamp = $_GET["timestamp"];
    #$nonce = $_GET["nonce"];
    #
    #$tmpArr = array($token, $timestamp, $nonce);
    #sort($tmpArr, SORT_STRING);
    #$tmpStr = implode($tmpArr);
    #$tmpStr = sha1($tmpStr);
    #
    #if ($tmpStr == $signature) {
    #    echo $_GET['echostr'];
    #} else {
    #    echo 'xx';
    #}

  //獲取token

  include_once "./token.php";

  //接收用戶消息
  $jsonString = file_get_contents("php://input");

  // file_put_contents(__DIR__.'/wechat.log',print_r($jsonString,true),8);
  
      if (!empty($jsonString) && is_string($jsonString)) {
      $postArr = json_decode($jsonString, true);
      //發送者openid
      $fromUsername = $postArr['FromUserName'];

      //內容
      $content = $postArr['Content'];

      // file_put_contents(__DIR__.'/wechat.log',print_r($content,true),8);
      
      $json_data = '{
            "touser":'.$fromUsername.',
            "msgtype":"text",
            "text":
            {
                 "content":'.$content.'
            }
          }';
     $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$token;

      $res = CurlPost($url,$json_data);
      var_dump($res); 
     
  }


 

  echo "success";
  exit;



  ?>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章