//获得access_token
function get_access_token()
{
$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".C("WX_APPID")."&secret=".C("WX_APPSECRET");
$access_token=curl_data($url);
return $access_token['access_token'];
}
//curl方法
function curl_data($url,$data = null){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
$info_result=json_decode($output,true);
return $info_result;
}
//绑定pid时,给pid发送消息
function custom_message($touser,$content){
$ACC_TOKEN=get_access_token();
$data = '{
"touser":"'.$touser.'",
"msgtype":"text",
"text":
{
"content":"'.$content.'"
}
}';
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$ACC_TOKEN;
$result = curl_data($url,$data);
$final = json_decode($result);
return $final;
}
上面是函授,下面是调用的
custom_message(发送者的openid,发送内容);