PHP发送微信模版消息
public function payResult($params) {
global $_GPC, $_W;
$weid = $this->_weid;
$order = pdo_fetch("SELECT id, status, hotelid, roomid FROM " . tablename('hotel2_order') . " WHERE id = {$params['tid']} AND weid = {$weid} LIMIT 1");
pdo_update('hotel2_order', array('paystatus' => 1), array('id' => $params['tid']));
if ($params['from'] == 'return') {
$roomid = $order['roomid'];
$room = pdo_fetch("SELECT score FROM " . tablename('hotel2_room') . " WHERE id = {$roomid} AND weid = {$weid} LIMIT 1");
$score = intval($room['score']);
if ($score) {
$from_user = $this->_from_user;
pdo_fetch("UPDATE " . tablename('hotel2_member') . " SET score = (score + " . $score . ") WHERE from_user = '".$from_user."' AND weid = ".$weid."");
pdo_fetch("UPDATE " . tablename('fans') . " SET credit1 = (credit1 + " . $score . ") WHERE from_user = '".$from_user."' AND weid = ".$weid."");
}
/*
发送模板消息
*/
$template_id="mYQugPDOABxe1Y9HVVZy8avP9inHsQAJuL_TJsU49y4";
$url='http://' . $_SERVER['SERVER_NAME'] . '/'.$this->createMobileUrl('orderdetail',array("id"=>$order['id']));
$color='#FF0000';
$sql = "SELECT o.*, h.title, h.address, h.phone";
$sql .= " FROM " .tablename('hotel2_order') ." AS o";
$sql .= " LEFT JOIN " .tablename('hotel2') ." AS h ON o.hotelid = h.id";
$sql .= " WHERE 1 = 1";
$sql .= " AND o.id = :id";
$sql .= " AND o.weid = :weid";
$params = array();
$params[':weid'] = $weid;
$params[':id'] = $order['id'];
$sql .= " LIMIT 1";
$item = pdo_fetch($sql, $params);
$paymethod="";
if($item['paytype']==1){
$paymethod="余额支付";
}elseif($item['paytype']==21){
$paymethod="微信支付";
}elseif($item['paytype']==22){
$paymethod="支付宝";
}else{
$paymethod="到店付款";
}
$remark="房间数量:".$item["nums"]."间\n房型名称:".$item["style"]."\n订单总价:¥".$item["sum_price"]."\n酒店电话:".$item["phone"]."\n酒店地址:".$item["address"]."\n付款方式:".$paymethod."\n房间将保留至次日中午12点,不能取消修改。";
$data=array(
"first"=>array(
"value"=>"您好,您已成功预订".$item["title"]."!",
"color"=>"#173177"
),
"OrderID"=>array(
"value"=>$item["ordersn"],
"color"=>"#173177"
),
"PersonName"=>array(
"value"=>$item["name"],
"color"=>"#173177"
),
"CheckInDate"=>array(
"value"=>date('Y-m-d',$item['btime']),
"color"=>"#173177"
),
"CheckOutDate"=>array(
"value"=>date('Y-m-d',$item['etime']),
"color"=>"#173177"
),
"remark"=>array(
"value"=>$remark,
"color"=>"#173177"
)
);
$data=json_encode($data);
$this->sendtempmsg($template_id,$url,$data,$color);
//end 发送模板消息
message('支付成功!', "/".$this->createMobileUrl('orderdetail',array("id"=>$order['id'])), 'success');
}
}
public function sendtempmsg($template_id, $url, $data, $topcolor) {
global $_W, $_GPC;
$from_user = $this->_from_user;
$tokens = $this->get_weixin_token();
//echo "token:".$tokens."..";
if (empty($tokens)) {
return;
}
$postarr = '{"touser":"' . $from_user . '","template_id":"' . $template_id . '","url":"' . $url . '","topcolor":"' . $topcolor . '","data":' . $data . '}';
$res = ihttp_post('https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $tokens, $postarr);
return true;
}
public function get_weixin_token() {
global $_W, $_GPC;
$account = $_W['account'];
if (is_array($account['access_token']) && !empty($account['access_token']['token']) && !empty($account['access_token']['expire']) && $account['access_token']['expire'] > TIMESTAMP) {
return $account['access_token']['token'];
} else {
if (empty($account['weid'])) {
message('参数错误.');
}
$appid = $account['key'];
$secret = $account['secret'];
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
$content = ihttp_get($url);
if (empty($content)) {
message('获取微信公众号授权失败, 请稍后重试!');
}
$token = @json_decode($content['content'], true);
if (empty($token) || !is_array($token)) {
message('获取微信公众号授权失败, 请稍后重试! 公众平台返回原始数据为: <br />' . $token);
}
if (empty($token['access_token']) || empty($token['expires_in'])) {
message('解析微信公众号授权失败, 请稍后重试!');
}
$record = array();
$record['token'] = $token['access_token'];
$record['expire'] = TIMESTAMP + $token['expires_in'];
$row = array();
$row['access_token'] = iserializer($record);
pdo_update('wechats', $row, array(
'weid' => $account['weid']
));
return $record['token'];
}
}
PHP发送微信模版消息的更多相关文章
- golang/beego 微信模版消息
// GO的微信SDK我用的是这个:https://github.com/silenceper/wechat // 发送模版消息 // UserNickName,UserMobile是发起预约的人的昵 ...
- 【模版消息】C#推送微信模版消息(Senparc.Weixin.MP.dll)
定义的模版内容: {{first.DATA}} 商品名称:{{product.DATA}} 商品价格:{{price.DATA}} 购买时间:{{time.DATA}} {{remark.DATA}} ...
- ThinkPHP3.2.3发送微信模板消息
一.开通模板消息功能 所有服务号都可以在功能->添加功能插件处看到申请模板消息功能的入口,但只有认证后的服务号才可以申请模板消息的使用权限并获得该权限:需要选择公众账号服务所处的2个行业,每月可 ...
- PHP开发微信模版消息换行的问题
微信是个坑!微信是个坑!微信是个坑!重要的时间说三遍 关键的地方是空白换行符到底是什么也不说,百度说是"\n":但是在发送消息的时候发现原样输出,发现json_encode对\n进 ...
- 应用jfinal发送微信模板消息的一个bug
严格来讲,这不是一个bug,只是我们应用的方式不对.微信发送模板消息的方法是: HttpUtils.post(sendApiUrl + AccessTokenApi.getAccessTokenStr ...
- php 实现发送微信模板消息(转)
<?php namespace Org\Weixin; /** * Created by PhpStorm. * User: StandOpen * Date: 15-1-7 * Time: 9 ...
- 微信小程序中发送模版消息注意事项
在微信小程序中发送模版消息 参考微信公众平台Api文档地址:https://mp.weixin.qq.com/debug/wxadoc/dev/api/notice.html#模版消息管理 此参考地址 ...
- C# 微信公众平台开发(4)-- 模版消息
微信公众平台开发 --发送模版消息 发送模版消息是微信服务号给某个用户发送模版消息,类似于APP的推送通知: 1.添加模版消息 在页面的左上 有一个添加功能插件的 按钮,如题 添加完成后,我们就可以在 ...
- python使用itchat发送微信消息提醒
最近在学习一点python,先找了找有趣的应用,实际修改跑了一下提高兴趣程度. 找到itchat,它的简介是这样的: “itchat是一个开源的微信个人号接口,使用python调用微信从未如此简单. ...
随机推荐
- 用Activator.CreateInstance代替new实现类的实例化(转)
一直想得到这样一个函数,输入一个类的名称为参数,返回一个相应的类的实例. 这在工厂模式中是非常有用的 这样,可以使程序有更高的扩展性,例如,,下面的例子 如果现在有一个类,专门用来计算交通工具的速度, ...
- Jersey(1.19.1) - Sub-resources
@Path may be used on classes and such classes are referred to as root resource classes. @Path may al ...
- 一段C程序分析
#include <stdio.h> #include <stdlib.h> void main() { int i; ; char ch; printf("请输入一 ...
- sqlserver中关于merge
merge: 在2008后被引入,它能将insert,Update,delete 简单并为一句,根据与源表连接的结果,对目标表进行插入,更新和删除操作例如:Merge是关于对于两个表之间进行操作的 C ...
- 百度ueditor编辑器背景不显示问题
网友办法:http://www.hongxuejing.com/hulianwang/ueditor_not_show_background-33.html 官方办法:http://fex-team. ...
- C# 使用Code First迁移更新数据库
三步完成迁移: 1. 启用迁移: Enable-Migrations Enable-Migrations -ContextTypeName Mvc4WebSite.Models.MvcGuestboo ...
- 用JS实现回文数的精准辨别!!!
笔者最近在一边看<JS高级程序设计3>一边在FCC上找题目练习啊.那叫一个爽.这不,刚刚用生命在课堂,寝室,实验室,图书馆等各种场所将第五章"引用类型"搞定,FCC便知 ...
- css设置网页打印样式
有三种方法 1. 为屏幕显示和打印分别准备一个css文件,如下所示: 用于屏幕显示的css: <link rel="stylesheet" href="css/n ...
- [GeekBand] STL与泛型编程(3)
本篇文章主要介绍泛型算法中的变易.排序.数值算法. 一. 变易算法 所谓变易算法是指那些改变容器中的对象的操作. 1.1 copy组 template <class InputIterator, ...
- (POJ 2318)TOYS 向量叉积
题目链接:http://poj.org/problem?id=2318 #include<stdio.h> #include<cstdlib> #include<cstr ...