天天看點

微信小程式調用客服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;



  ?>
           

繼續閱讀