### [微信小程序错误码47001是什么原因](https://www.prosaas.cn/article/16782) **Published:** 2020-03-26T07:30:41 **Author:** 5201314 **Excerpt:** 微信小程序出现47001错误是因为格式不对导致的。微信小程序 出现47001 data format erro… ![](https://img.php.cn/upload/article/000/000/039/5e7c5919223fe128.jpg) 微信小程序出现47001错误是因为格式不对导致的。 微信小程序 出现47001 data format error解决办法: 看下错误: ![](https://img.php.cn/upload/image/236/449/777/1585207293476707.jpg) 主要原因是请求的数据不是json格式引起的。 分享下我用的代码和函数:  发送模板消息 public function sendmessage(){ $data=$\_POST=json\_decode(file\_get\_contents('php://input'), TRUE); $access\_token=$this->getAccessToken(); $request\_url='https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access\_token='.$access\_token; $request\_data=array( 'touser'=>$data\['touser'\],//接收者(用户)的 openid 'template\_id'=>$data\['template\_id'\],//所需下发的模板消息的id 'page'=>$data\['page'\],//点击模板卡片后的跳转页面 'form\_id'=>$data\['form\_id'\],//表单提交场景下,为 submit 事件带上的 formId;支付场景下,为本次支付的 prepay\_id 'data'=>$data\['data'\],//"keyword1": {"value": "339208499", "color": "#173177"} 'emphasis\_keyword'=>$data\['emphasis\_keyword'\]//模板需要放大的关键词,不填则默认无放大 ); $return=json\_decode(https\_request($request\_url,$request\_data,'json'),true); $this->response($return,'json'); } 发送请求 function https\_request($url,$data,$type){ if($type=='json'){//json $\_POST=json\_decode(file\_get\_contents('php://input'), TRUE); $headers = array("Content-type: application/json;charset=UTF-8","Accept: application/json","Cache-Control: no-cache", "Pragma: no-cache"); $data=json\_encode($data); } $curl = curl\_init(); curl\_setopt($curl, CURLOPT\_URL, $url); curl\_setopt($curl, CURLOPT\_SSL\_VERIFYPEER, FALSE); curl\_setopt($curl, CURLOPT\_SSL\_VERIFYHOST, FALSE); if (!empty($data)){ curl\_setopt($curl, CURLOPT\_POST, 1); curl\_setopt($curl, CURLOPT\_POSTFIELDS,$data); } curl\_setopt($curl, CURLOPT\_RETURNTRANSFER, 1); curl\_setopt( $ch, CURLOPT\_HTTPHEADER, $headers ); $output = curl\_exec($curl); curl\_close($curl); return $output; } 推荐:《小程序开发教程》 以上就是微信小程序错误码47001是什么原因的详细内容,更多请关注知企PROSAAS其它相关文章! **Tags:** Error, format, json, 微信小程序 **Categories:** 后端开发 ---