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发送微信模版消息的更多相关文章

  1. golang/beego 微信模版消息

    // GO的微信SDK我用的是这个:https://github.com/silenceper/wechat // 发送模版消息 // UserNickName,UserMobile是发起预约的人的昵 ...

  2. 【模版消息】C#推送微信模版消息(Senparc.Weixin.MP.dll)

    定义的模版内容: {{first.DATA}} 商品名称:{{product.DATA}} 商品价格:{{price.DATA}} 购买时间:{{time.DATA}} {{remark.DATA}} ...

  3. ThinkPHP3.2.3发送微信模板消息

    一.开通模板消息功能 所有服务号都可以在功能->添加功能插件处看到申请模板消息功能的入口,但只有认证后的服务号才可以申请模板消息的使用权限并获得该权限:需要选择公众账号服务所处的2个行业,每月可 ...

  4. PHP开发微信模版消息换行的问题

    微信是个坑!微信是个坑!微信是个坑!重要的时间说三遍 关键的地方是空白换行符到底是什么也不说,百度说是"\n":但是在发送消息的时候发现原样输出,发现json_encode对\n进 ...

  5. 应用jfinal发送微信模板消息的一个bug

    严格来讲,这不是一个bug,只是我们应用的方式不对.微信发送模板消息的方法是: HttpUtils.post(sendApiUrl + AccessTokenApi.getAccessTokenStr ...

  6. php 实现发送微信模板消息(转)

    <?php namespace Org\Weixin; /** * Created by PhpStorm. * User: StandOpen * Date: 15-1-7 * Time: 9 ...

  7. 微信小程序中发送模版消息注意事项

    在微信小程序中发送模版消息 参考微信公众平台Api文档地址:https://mp.weixin.qq.com/debug/wxadoc/dev/api/notice.html#模版消息管理 此参考地址 ...

  8. C# 微信公众平台开发(4)-- 模版消息

    微信公众平台开发 --发送模版消息 发送模版消息是微信服务号给某个用户发送模版消息,类似于APP的推送通知: 1.添加模版消息 在页面的左上 有一个添加功能插件的 按钮,如题 添加完成后,我们就可以在 ...

  9. python使用itchat发送微信消息提醒

    最近在学习一点python,先找了找有趣的应用,实际修改跑了一下提高兴趣程度. 找到itchat,它的简介是这样的: “itchat是一个开源的微信个人号接口,使用python调用微信从未如此简单. ...

随机推荐

  1. webkit,HTML5头部标签

    大家都知道在移动前端开发中添加一些webkit专属的HTML5头部标签,帮助浏览器更好解析html代码,更好地将移动web前端页面表现出来.本文整理一些HTML5头部<meta>标签常用的 ...

  2. less-2

    样式内嵌: 生成css:   样式运算:   生成的css文件:

  3. Sql Server关于text类型的替换

    UPDATE Store SET Body=replace(convert(varchar(8000),Body),'http://120.89.46.68:8007','')

  4. Yii zii.widgets.grid 隐藏列 方便js获取隐藏值

    array( 'name' => $data->is_audit, 'value' => '$data->is_audit', 'headerHtmlOptions' => ...

  5. C# DateTime格式化

    DateTime. ToString() -- :: ToBinary() - ToFileTime() ToFileTimeUtc() ToLocalTime() -- :: ToLongDateS ...

  6. iOS夯实:内存管理

    iOS夯实:内存管理 文章转自 内存管理 最近的学习计划是将iOS的机制原理好好重新打磨学习一下,总结和加入自己的思考. 有不正确的地方,多多指正. 目录: 基本信息 旧时代的细节 新时代 基本信息 ...

  7. 使用AngularJS构建大型Web应用

    AngularJS是由Google创建的一种JS框架,使用它可以扩展应用程序中的HTML词汇,从而在web应用程序中使用HTML声明动态内容.在该团队工作的软件工程师Brian Ford近日撰写了一篇 ...

  8. 快速搭建MongoDB分布式集群

    目录Outline 1. prerequisites 2. steps to follow3. configuring the cluster4. a little test to see 1. Pr ...

  9. 按按钮调用PHP function函数

    首先,请大家看一段HTML代码: <html> <head> </head> <body> <input type=button on_click ...

  10. Xamarin 实现android gridview 多选

    参考文章:http://blog.csdn.net/zhouyuanjing/article/details/8372686 GridView初始化代码: gridViewStudent = Find ...