PHP之微信企业号推送信息

来源:互联网 发布:全国工商企业数据爬虫 编辑:程序博客网 时间:2024/05/09 12:03
1、微信企业号需要员工关注微信企业号,添加成员并通过验证
###########**********微信推送部分***********#########################//推送信息public function getPush($userid , $agentid , $message){$userinfo = $this->getToken();//获取access_token$access_token = $userinfo['access_token'];$sendmsg_url = "https://qyapi.weixin.qq.com/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;//推送失败//}}//获取tokenpublic function getToken(){$corpid = "wx741c60f989cdfd48"; $corpsecret = "Qf6ioo2wEGvQuGWVYPy-b1CeJNLbvHIuX2JMrnhvepH9gIfcl6OViG8hkofBC7nH"; $Url="https://qyapi.weixin.qq.com/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) == "https://" ? 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,必须是双引号,单引号发送不成功!!!
1 0
原创粉丝点击