微信开发:客服接口向用户发送消息

 

发送文本消息:

$access_token = "";

$url='https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;
$content = '{
    "touser":"'.$openid.'",
    "msgtype":"text",
    "text":
    {
         "content":"'.$content.'"
    }
}';  
$htt = $this->https_post($url,$content);

var_dump($htt);

 

public function https_post($url,$data){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($curl);
        if(curl_errno($curl)) {
            return 'Errno'.curl_errno($curl);
        }
        curl_close($curl);
        return $result;
    }

posted @ 2015-08-01 10:29  王宇walkOn  阅读(561)  评论(0编辑  收藏  举报