微信公众号客服接口

微信公众号客服接口,用于关注时推送多条信息

public function send($rts=array()){
        if(empty($rts['openid'])) return;
        $openid = $rts['openid'];
        $str = $rts['content'];
        $access_token = $this->getAccessToken($appId,$appSecret);
        $data='{"touser": "'.$openid.'","msgtype": "text","text": {"content": "'.$str.'"}}';
        $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;
        return $this->curlPost($data,$url,0);
}
    /**
     * 获取access_token
     * @return string
     */
    public function getAccessToken($appid,$appsecret)
    {
            $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret;
            $con = $this->curlGet($url);
            $json = json_decode($con,true);
            $access_token = param($json,'access_token'); //获取 access_token
            return $access_token;
    }

    /**
     * curl Get请求
     * @param $url
     * @return mixed
     */
    private function curlGet($url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $temp = curl_exec($ch);
        return $temp;
    }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容