明星隆胸前后对比照thinkphp发模板消息/**
* @description: 发循环
* @param {*}
* @return {*}
*/
public function sendall(){
$all_openid=$this->tosendall();
foreach($all_openid as$value){
$res= Db::name('*****')->where('open_id',$value)->find();
if(!empty($res)){
$this->set_msg($res);
}
}
exit;
}
/**
* @description: curl
* @param {*}
* @return {*}
*/
public function tosendall(){
$access_token=getAccesstoken();
$url="api.weixin.qq/cgi-bin/user/get?access_token={$access_token}&next_openid=";
$ch=curl_init($url);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
女主很妩媚的小说
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
$data=curl_exec($ch);中国恐怖电影排行榜
$data=json_decode($data,true);
return$data['data']['openid'];丁嘉丽个人资料
}
/**
* @description: 发送消息
* @param {*} $openid
* @return {*}
*/
public function set_msg($values){
$access_token=getAccesstoken();
$openid=$values['open_id'];
$username=$values['username'];
$datetime=date("Y-m-d",time());
$template=array(
"touser"=>"$openid",//⽤户openid
"template_id"=>"*******",//你的模板id
"url"=>"",//跳转链接
"data"=>array(
'first'=>array('value'=>urlencode("今天您打卡了么?")),
'keyword1'=>array('value'=>urlencode("$username")),
'keyword2'=>array('value'=>urlencode("$datetime")),
'keyword3'=>array('value'=>urlencode("您还未打卡")),
)
);
$json_template=json_encode($template);
$url="api.weixin.qq/cgi-bin/message/template/send?access_token=".$access_token;
$json=$this->curl_post($url,urldecode($json_template));
$rs=json_decode($json,true);
// if ($rs['errcode'] == 0) {
//    echo 'ok';
// } else {
//    echo "no";
//    print_r($rs);
// }
}
function curl_post($url,$data){
$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);
return$output;
}
公共函数库
function getAccessToken(){
// access_token 应该全局存储与更新,以下代码以写⼊到⽂件中做⽰例
// 如果是企业号⽤以下URL获取access_token
// $url = "qyapi.weixin.qq/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
$cacheKey='cache:access:token';
if(Cache::has($cacheKey)){
return Cache::get($cacheKey);
}else{
$url="api.weixin.qq/cgi-bin/token?grant_type=client_credential&appid=".config('user.appid')."&secret=".config('user.secret');
$res=json_decode(httpGet($url));
$access_token=$res->access_token;
Cache::set($cacheKey,$access_token,60*5);
return$access_token;
}
}
function httpGet($url,$data=null,$method='get',$header=array("content-type: application/json"),$https=true,$timeout=5){
明初风流$method=strtoupper($method);
$ch=curl_init();//初始化
curl_setopt($ch,CURLOPT_URL,$url);//访问的URL
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);//只获取页⾯内容,但不输出
乔四玩过的女明星
if($https){
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);//https请求验证证书
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);//https请求不验证HOST
}
if($method!="GET"){
if($method=='POST'){
curl_setopt($ch,CURLOPT_POST,true);//请求⽅式为post请求
}
if($method=='PUT'||strtoupper($method)=='DELETE'){
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,$method);//设置请求⽅式
}
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//请求数据
}
curl_setopt($ch,CURLOPT_TIMEOUT,$timeout);
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);//模拟的header头
//curl_setopt($ch, CURLOPT_HEADER, false);//设置不需要头信息
$result=curl_exec($ch);//执⾏请求
curl_close($ch);//关闭curl,释放资源
return$result;
}