php数组转换成json格式。

时间:2023-06-01 18:28:32
   {
"touser":"OPENID",
"template_id":"ngqIpbwh8bUfcSsECmogfXcV14J0tQlEpBO27izEYtY",
"url":"http://weixin.qq.com/download",
"data":{
"first": {
"value":"恭喜你购买成功!",
"color":"#173177"
},
"keynote1":{
"value":"巧克力",
"color":"#173177"
},
"keynote2": {
"value":"39.8元",
"color":"#173177"
},
"keynote3": {
"value":"2014年9月22日",
"color":"#173177"
},
"remark":{
"value":"欢迎再次购买!",
"color":"#173177"
}
}
} public function settemplateMsg(){ $templateID = "oCn07pNLLCgUP9KN4T34sCs69nIqrBgtuCtAdVWaHOg";
$posttemepleUrl ="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$this->access_token; $postData = array();
$postData['touser']= "o2Q4wtwk4NlLqy7QwTWG5vc8RVus";
$postData['template_id']= $templateID;
$postData['url']= "http://m.ancun.org/wxmsg/index.php/home/attention"; $templArr= array();
$templArr['first'] = array('value'=>'有美女给你发信息啦','color'=>'#173177');
$templArr['keyword1'] = array('value'=>'明天你有时间吗。我要你出来一下。','color'=>'#173177');
$templArr['keyword2'] = array('value'=>'存宝系统 ','color'=>'#173177');
$templArr['keyword3'] = array('value'=>'王您码','color'=>'#173177');
$templArr['keyword4'] = array('value'=>'2014年9月22日','color'=>'#173177');
$templArr['remark'] = array('value'=>'欢迎再次使用。','color'=>'#173177'); $postData['data']= $templArr; $postData = json_encode($postData); $result = $this->http_request($posttemepleUrl,$postData);
return json_decode($result,true); }