Solution to 47001 data format error in the Applet: 47001 error
Solution to 47001 data format error in a Applet
Check the error:
The main reason is that the requested data is not in json format.
Share the code and functions I used:
Send template message
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'], // recipient (User) openid 'template _ id' => $ data ['template _ id'], // The id 'page' => $ data ['page'] of the template message to be sent. // click 'form _ id' => $ data ['form _ id'] on the jump page after the template card. // In the form submission scenario, it is the formId of the submit event; in the payment scenario, prepay_id 'data' => $ data ['data'] for this payment, // "keyword1": {"value": "339208499 ", "color": "#173177"} 'emphasis _ keyword' => $ data ['emphasis _ keyword'] // keywords to be enlarged in the template. If this parameter is left blank, the template is not enlarged by default ); $ return = json_decode (https_request ($ request_url, $ request_data, 'json'), true); $ this-> response ($ return, 'json ');}
Send request
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;}
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!