微信公众号客服接口,用于关注时推送多条信息
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;
}