用thinkphp实现 <?php

namespace Org\Weixin;

/**

* Created by PhpStorm.

* User: StandOpen

* Date: 15-1-7

* Time: 9:41

*/

class OrderPush

{

protected $appid;

protected $secrect;

protected $accessToken;

function __construct($appid, $secrect)

{

$this->appid = $appid;

$this->secrect = $secrect;

$this->accessToken = $this->getToken($appid, $secrect);

}

/**

* 发送post请求

* @param string $url

* @param string $param

* @return bool|mixed

*/

function request_post($url = '', $param = '')

{

if (empty($url) || empty($param)) {

return false;

}

$postUrl = $url;

$curlPost = $param;

$ch = curl_init(); //初始化curl

curl_setopt($ch, CURLOPT_URL, $postUrl); //抓取指定网页

curl_setopt($ch, CURLOPT_HEADER, 0); //设置header

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上

curl_setopt($ch, CURLOPT_POST, 1); //post提交方式

curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);

$data = curl_exec($ch); //运行curl

curl_close($ch);

return $data;

}

/**

* 发送get请求

* @param string $url

* @return bool|mixed

*/

function request_get($url = '')

{

if (empty($url)) {

return false;

}

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$data = curl_exec($ch);

curl_close($ch);

return $data;

}

/**

* @param $appid

* @param $appsecret

* @return mixed

* 获取token

*/

protected function getToken($appid, $appsecret)

{

if (S($appid)) {

$access_token = S($appid);

} else {

$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $appsecret;

$token = $this->request_get($url);

$token = json_decode(stripslashes($token));

$arr = json_decode(json_encode($token), true);

$access_token = $arr['access_token'];

S($appid, $access_token, 720);

}

return $access_token;

}

/**

* 发送自定义的模板消息

* @param $touser

* @param $template_id

* @param $url

* @param $data

* @param string $topcolor

* @return bool

*/

public function doSend($touser, $template_id, $url, $data, $topcolor = '#7B68EE')

{

/*

* data=>array(

'first'=>array('value'=>urlencode("您好,您已购买成功"),'color'=>"#743A3A"),

'name'=>array('value'=>urlencode("商品信息:微时代电影票"),'color'=>'#EEEEEE'),

'remark'=>array('value'=>urlencode('永久有效!密码为:1231313'),'color'=>'#FFFFFF'),

)

*/

$template = array(

'touser' => $touser,

'template_id' => $template_id,

'url' => $url,

'topcolor' => $topcolor,

'data' => $data

);

$json_template = json_encode($template);

$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $this->accessToken;

$dataRes = $this->request_post($url, urldecode($json_template));

if ($dataRes['errcode'] == 0) {

return true;

} else {

return false;

}

}

}

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

php查询mysql增加模板消息_php 实现发送微信模板消息相关推荐

  1. php+实现群发微信模板消息_php实现发送微信模板消息的方法,php信模板消息_PHP教程...

    php实现发送微信模板消息的方法,php信模板消息 本文实例讲述了php实现发送微信模板消息的方法.分享给大家供大家参考.具体如下: 该方法基于thinkphp实现实现,具体OrderPush.cla ...

  2. 模板消息 php实例,PHP微信模板消息操作示例

    本文实例讲述了PHP微信模板消息操作方法.分享给大家供大家参考,具体如下: 微信SDK: class Oauth { //获得全局access_token public function get_to ...

  3. 发送微信模板消息+定时任务

    在用户购买会员卡后的第二天下午四点发送微信模板消息 在pom.xml里面配置 <dependency><groupId>net.coobird</groupId>& ...

  4. openid无效什么意思_发送微信模板消息,返回OpenId无效

    发送订单创建成功通知模板 请求地址  https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN ...

  5. php多进程更新微信用户信息,php之swoole多进程发送微信模板消息

    本文主要按照给快到期的微信用户发送模板消息,提醒续费来讲解,主要和大家分享php之swoole多进程发送微信模板消息,希望能帮助到大家. 首先拿到快到期的用户, 每天大概800-2000不等,感觉压力 ...

  6. php redis微信发红包,高阶篇二 使用Redis队列发送微信模版消息

    # 高阶篇二 使用Redis队列发送微信模版消息 > 此命令行执行任务的方法类比较复杂 他需要命令行运行才会有效 > 命令行源码以及创建方法 参见上节 https://www.kanclo ...

  7. php网站为微信发信息,PHP发送微信模版消息代码

    做微信开发的人都知道微信模版消息的重要性,今天给大家分享一篇使用PHP来发送微信模版消息的demo,废话少说,进入正题. 1.创建一个发送模版消息的类,我这里命名为"templatesMes ...

  8. php查询mysql放到数组中_php查询mysql数据库并将结果保存到数组的方法

    本文实例讲述了php查询mysql数据库并将结果保存到数组的方法..具体分析如下: 这里主要用到了mysql_fetch_assoc函数 mysql_fetch_assoc语法如下: array my ...

  9. php查询mysql表里的数据_php查询mysql数据表记录实现代码

    php与mysql是黄金组合,现在我们来讲一下关于php查询mysql数据库记录实现,主要会用到函数mysql_connect mysql_query mysql_select_db mysql_fe ...

  10. php查询mysql表里的数据_PHP/MYSQL 查询大数据/遍历表

    PHP:PHP 5.3.6 (cli) (built: Jun 15 2011 16:29:50) MYSQL:5.1.51 如果我们有的一张表有几百万或几千万的记录,我们要使用 PHP 将所有的记录 ...

最新文章

  1. 图很难理解?看这篇图论基础与图存储结构就够了
  2. Android采用pm实现静默安装(降级安装)的解决方案
  3. leetcode523 Continuous Subarray Sum
  4. C/Cpp / C++ 构造函数和析构函数可以是虚函数吗
  5. 同工不同酬,年薪 50 万美金的工程师到底有什么神本事?
  6. matalotlib(2)
  7. c语言入门函数大全,C语言函数大全(适合初学者).doc
  8. Serverless 是一种思想状态
  9. MongoDB+MongoVUE安装及入门
  10. ALSA 音频工具 amixer、aplay、arecord
  11. html5 页面3d显示不出来的,Word页面视图内容为什么在大纲视图上显示不出来?
  12. AT070TN83 V1.0 背光不亮
  13. CRM系统源码PHP开发
  14. 《大话数据结构》参考
  15. mac os x excel 单元格换行
  16. 【错误记录】Kotlin 报错 ( Some kotlin libraries attached to this project were compiled with a newer kotlin )
  17. 虾神的csdn技术博客
  18. nano编辑器的使用
  19. python作业_python小作业
  20. 2022哈工大软件构造lab1小结(知识点)

热门文章

  1. BZOJ3171:[TJOI2013]循环格
  2. PHP中的逻辑运算符的优先级
  3. Appcan将支持在线编译提交App Store
  4. ESP8266(2)
  5. Python游戏开发入门2 壁球小游戏与图像的基本使用
  6. Atitit json数据操作法 目录 1. 2. 常用json函数类型四大类型 crud判断 1 1.1. 2.1. 创建json 2 1 1.2. 2.2. 选择与读取 3读取数据读取key
  7. Atitit 项目中的勋章体系,,mvp建设 ,荣典体系建设
  8. atitit. access token是什么??微信平台公众号开发access_token and Web session保持状态机制
  9. atitit.404错误的排查流程总结
  10. atitit.gui界面纵向居中总结