public function index(){
$data = array(
'openid' => 'o-kxTwYQVktypbhqgAOajrfwWyuQ',
'url' => 'fangchan.580ck.com/index.php/Muban/index',
'title' => '通知内容',
'info' => '商品名',
'points' => '价格',
'remark' => '备注信息'
);
$sendMes = new sendMessage ();
$sendMes->sendTempleMessage ( $data );
}这个是微信类的<?php
/**
* 微信模板推送 WxTemple.class..php
* ============================================================================
* 版权所有 (C) 2015-2016 壹尚科技有限公司,并保留所有权利。
* 网站地址: http://www.ethank.com.cn
* ----------------------------------------------------------------------------
* 许可声明:这是一个开源程序,未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
* ============================================================================
* Author: 勾国印 (gouguoyin@ethank.com.cn)
* Date: 2016年5月18日 下午11:23:40
*/
namespace Com;
class sendMessage {
// 推送模版消息
function getAuthParam() {
$apiKey = '';
$apiSecret = '';
$timestamp = time();
return array(
'apiKey' => $apiKey,
'timestamp' => $timestamp,
'sig' => md5($apiKey . $apiSecret . $timestamp),
);
}
function sendTempleMessage($data) {
$param['type'] = 'template';
$param['templateId'] = 'l359TxOojt8_Rc63ICreCeByKKAyEMSu6Q1s659QnBg';
$param['topcolor'] = '#04a7f9';
//模版消息跳转地址
$param['url'] = $data['url'];
$param['toUsers'] = $data['openid'];
$param['data'] = $this->getCardTemplateData($data['title'],$data['points'],$data['info'],$data['remark']);
$send = $this->sendTempleMsg($param);
}
//模版消息
function getCardTemplateData($title,$points,$info,$remark) {
$templateData = array(
'first' => array(
'value' => $title,
'color' => '#0e356e'
),
'orderMoneySum' => array(
'value' => $points,
'color' => '#2832e1'
),
'orderProductName' => array(
'value' => $info,
'color' => '#0e356e'
),
'Remark' => array(
'value' => $remark,
'color' => '#0e356e'
)
);
return json_encode($templateData);
}
function sendDeliverTempleMessage($data) {
$param['type'] = 'template';
$param['templateId'] = 'TM00001';
$param['topcolor'] = '#04a7f9';
//模版消息跳转地址
$param['url'] = $data['url'];
$param['toUsers'] = $data['openid'];
$param['data'] = $this->getDeliverCardTemplateData($data['title'],$data['order_id'], $data['remark']);
$send = $this->sendTempleMsg($param);
}
//模版消息
function getDeliverCardTemplateData($title,$order_id,$remark) {
$templateData = array(
'first' => array(
'value' => $title,
'color' => '#0e356e'
),
'OrderSn' => array(
'value' => $order_id,
'color' => '#2832e1'
),
'OrderStatus' => array(
'value' => '已发货',
'color' => '#0e356e'
),
'remark' => array(
'value' => $remark,
'color' => '#0e356e'
)
);
return json_encode($templateData);
}
//set temple by one
function sendTempleMsg($param) {
$sendParam = array(
'a' => 'Send',
'm' => 'sendTemplate'
);
$sendParam = array_merge($this->getAuthParam(), $sendParam);
$sendParam = array_merge($param, $sendParam);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://weixin.qq.com/download');
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_POST, 1);
$body = http_build_query($sendParam);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$httpInfo = curl_getinfo($curl);
curl_close($curl);
// echo $response;
return $response;
}
} 最佳答案