微信模板消息推送问题
鲸落JL 2015-09-26 06:46:31 参数这些正确不报错.运行到最后返回的Array ( [errcode] => 0 [errmsg] => ok [msgid] => 214533024 ) 也没问题.
但是微信上什么反应也没有,公众号是认证过的服务号,这是怎么回事?
代码如下,
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;
}
define('WX_APPID', 'xxxxxx');
define('WX_SECRET', 'xxxxxx');
define('OpenID', 'xxxxxx');
define('TemplateID', 'LDw_t-aA387-NZc4BkyZHwvJW6RN7DKWecTCl4exCAw');
define('Url', 'http://www.xxxxxx.net/wx_sample.php');
$json_token=http_request("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".WX_APPID."&secret=".WX_SECRET);
$row=json_decode($json_token,true);
$access_token = $row["access_token"];
//模板消息
$template=array(
'touser' => OpenID,
'template_id' => TemplateID,
'url' => Url,
'topcolor'=>"#7B68EE",
'data'=>array(
'first'=>array('value'=>urlencode("您好a在要,您有新的订单"),'color'=>"#FF0000"),
'keyword1'=>array('value'=>urlencode(date("Y-m-d H:i:s")),'color'=>'#FF0000'),
'keyword2'=>array('value'=>urlencode('这是测试'),'color'=>'#FF0000'),
'keyword3'=>array('value'=>urlencode('这是测试'),'color'=>'#FF0000'),
'keyword4'=>array('value'=>urlencode('这是测试'),'color'=>'#FF0000'),
'keyword5'=>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=".$access_token;
$res=http_request($url,urldecode($json_template));
$res=json_decode($res,true);
if ($res["errcode"]==0){
echo '发送成功';
}
print_r($res);