记住用户名密码
<span style="color:#006600;">###########**********微信推送部分***********######################### //推送信息 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;//推送失败 //} } //获取token public 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; }###########**********微信推送部分***********######################### </span>
注意:$data,必须是双引号,单引号发送不成功!!!
- 调用 $this->getPush($userid , $agentid , $message);
目前有 0 条留言 其中:访客:0 条, 博主:0 条