private function httpPost($url, $data) {
print_r($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_HEADER, 0); //设置header
curl_setopt($curl, CURLOPT_URL, $url);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}
//发送请求
$url = ‘https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=’.$token;
$data = array();
$data = '{
“touser”: “’.$params->openid.’”,
“template_id”: “x-1Pudsnd1k-z3Ms9cClcmP0t9Fei1tODgjFRHtnWoQ”,
“page”: “/example/regintro/regintro”,
“form_id”: “’.$params->formId.’”,
“data”: {
“keyword1”: {
“value”: “339208499”,
“color”: “#173177”
},
“keyword3”: {
“value”: “2015年01月05日 12:30”,
“color”: “#173177”
},
“keyword2”: {
“value”: “123232”,
“color”: “#173177”
}
},
“emphasis_keyword”: “keyword1.DATA”
}’;
$a = json_decode($data, true);
$res = $this->httpPost($url, $a);
//发送的结果
{“errcode”:47001,“errmsg”:“data format error hint: [zie7ma0905ge25]”}
是为何?