博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
微信发送模版消息,PHP代码简单案例
阅读量:6880 次
发布时间:2019-06-26

本文共 1862 字,大约阅读时间需要 6 分钟。

function http_request($url,$data=array()){      $ch = curl_init();      curl_setopt($ch, CURLOPT_URL, $url);      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);      // POST数据      curl_setopt($ch, CURLOPT_POST, 1);      // 把post的变量加上      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);      $output = curl_exec($ch);      curl_close($ch);      return $output;  }function send_wx_msg(){        $access_token=$this->http_request("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $this->APPID . "&secret=" . $this->APPSECRET);        $access_token=json_decode($json_token,true);        //获得access_token        $this->access_token=$access_token['access_token'];        //echo $this->access_token;exit;        //模板消息        $template=array(            'touser'=>'o8BlDv8Wy6t99QnbcOgmYgUxj///openid',            'template_id'=>"zgnQX1A-0jXK-ghw0d3xjxHIKdKpEQZjpUSkDTNZwOA",            'url'=>"http://neweb.top",            'topcolor'=>"#7B68EE",            'data'=>array(                'first'=>array('value'=>urlencode("恭喜你成功升级为钻石会员。"),'color'=>"#FF0000"),                'account'=>array('value'=>urlencode("戴先生"),'color'=>'#FF0000'),                'time'=>array('value'=>urlencode(date("Y-m-d H:i:s")),'color'=>'#FF0000'),                'type'=>array('value'=>urlencode('免费升级'),'color'=>'#FF0000'),                'remark'=>array('value'=>urlencode('恭喜你升级为钻石会员,点击查看会员特权。'),'color'=>'#FF0000'),            ));        $json_template=json_encode($template);        $url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$this->access_token;        $res=$this->http_request($url,urldecode($json_template));        //if ($res['errcode']==0) echo '发送成功';  }

 

转载于:https://www.cnblogs.com/phper12580/p/9836216.html

你可能感兴趣的文章
【Qt笔记】使用流处理 XML
查看>>
指针的使用
查看>>
5-pandas基础运算
查看>>
php判断IP跳转区域二级域名
查看>>
百度webupload--上传图片功能---插件使用
查看>>
Java深、浅克隆(clone)
查看>>
如何在View上不用UIImageView重新绘制一张图片?
查看>>
实现控制器(Controller)
查看>>
好多年前写的一个C++事件回调工具
查看>>
python3使用logging日志记录
查看>>
servlet3中jar的web资源携带
查看>>
3D打印将对零售模式产生颠覆影响,能否抓住机遇
查看>>
不用加减乘除实现加法
查看>>
Android SD卡 文件或目录拷贝、复制、粘贴
查看>>
git命令与github使用(转主要看向远程仓库推内容)
查看>>
JAVA生成四位数的验证码
查看>>
讯飞语音错误码大全
查看>>
编译器错误消息: CS0433: The type 'global_asax' exists in both 'App_global.asax
查看>>
原生ajax显示php后台内容
查看>>
Android 富文本装饰器Spannable
查看>>