PHP之企业号推送信息
PHP之企业号推送信息1、企业号需要员⼯关注企业号,添加成员并通过验证
>>#**********推送部分***********>>>>>
//推送信息
public function getPush($userid , $agentid , $message){
$userinfo = $this->getToken();//获取access_token
$access_token = $userinfo['access_token'];
$sendmsg_url = "qyapi.weixin.qq/cgi-bin/message/send?access_token=".$access_token;
$data="{\"touser\":\"$userid\",\"msgtype\":\"text\",\"agentid\":$agentid,\"text\":{\"content\":\"$message\"},\"safe\":0}"; $res = $this->curlPost($sendmsg_url,$data);
$errmsg=json_decode($res)->errmsg;
//if($errmsg==="ok"){;
//return 1;//推送成功
//}else{
//return 0;//推送失败
//}
}
//获取token
public function getToken(){
$corpid = "wx741c60f989cdfd48";
$corpsecret = "Qf6ioo2wEGvQuGWVYPy-b1CeJNLbvHIuX2JMrnhvepH9gIfcl6OViG8hkofBC7nH";
$Url="qyapi.weixin.qq/cgi-bin/gettoken?corpid=".$corpid."&corpsecret=".$corpsecret;
$res = $this->curlPost($Url);
$access_token=json_decode($res)->access_token;
$userinfo = array();
$userinfo['access_token']=$access_token;
return $userinfo;
}
//定义curl⽅法
public function curlPost($url,$data=""){
$ch = curl_init();
$opt = array(
CURLOPT_URL    => $url,
CURLOPT_HEADER  => 0,
CURLOPT_POST    => 1,
CURLOPT_POSTFIELDS      => $data,
CURLOPT_RETURNTRANSFER  => 1,
CURLOPT_TIMEOUT        => 20
);
企业号申请$ssl = substr($url,0,8) == "" ? TRUE : FALSE;
if ($ssl){
$opt[CURLOPT_SSL_VERIFYHOST] = 2;
$opt[CURLOPT_SSL_VERIFYPEER] = FALSE;
}
curl_setopt_array($ch,$opt);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
>>#**********推送部分***********>>>>>
调⽤ $this->getPush($userid , $agentid , $message);
注意:$data,必须是双引号,单引号发送不成功

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。

发表评论