Php version of WeChat store API secondary development and use example

Source: Internet
Author: User
This article describes the second API development and usage of the php version. For your reference, this article describes the second API development and usage of the php version store. We will share this with you for your reference. The details are as follows:

1. weixiaodian. php page:

 ID = $ ID; $ this-> sLogisticsList ();} public function cUrlRequest ($ url, $ data = null) {$ 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, expires, 1 ); $ output = curl_exec ($ curl); curl_close ($ curl); return $ output;} // Obtain the ACCESSTOKEN public function sAcessToken () {$ this-> HandleAT = $ this-> gAccessToken (); if ($ this-> HandleAT-> expire_time <time () {$ appid = $ this-> AppID; $ appsecret = $ this-> AppSecret; $ ur L = "https://api.weixin.qq.com/cgi-bin/token? Grant_type = client_credential & appid = ". $ appid." & secret = ". $ appsecret; $ result = https_request ($ url); // echo'
'; Var_dump ($ result); die; $ jsoninfo = json_decode ($ result, true); $ access_token = $ jsoninfo ["access_token"]; $ this-> pAccessToken ($ access_token); return $ access_token;} else {return $ this-> HandleAT-> access_token;} // Save the ACCESSTOKEN public function pAccessToken ($ accesstoken) {$ Path = $ _ SERVER ['document _ root']. "/jSon_file/access_token _". $ this-> ID. ". json "; // print_r ($ Path); if (! File_exists ($ Path) {touch ($ Path); chmod ($ Path, 0777);} $ data ['expire _ time'] = time () + 7000; $ data ['Access _ token'] = $ accesstoken; $ fp = fopen ($ Path, "w"); fwrite ($ fp, json_encode ($ data )); fclose ($ fp);} // read ACCESSTOKEN public function gAccessToken () {$ Path = $ _ SERVER ['document _ root']. "/jSon_file/access_token _". $ this-> ID. ". json "; if (! File_exists ($ Path) {$ data ['expire _ time'] = 0; $ data ['Access _ token'] = '';} else {$ data = json_decode (file_get_contents ($ Path); // print_r ($ data);} return $ data ;} // Obtain all products public function gStateProduct ($ state = 0 ){// https://api.weixin.qq.com/merchant/getbystatus?access_token= ACCESS_TOKEN // {"status": 0} $ this-> AccessToken = $ this-> sAcessToken (); $ url =" https://api.weixin.qq.com/merchant/getbystatus?access_token= ". $ This-> AccessToken; // print_r ($ this-> AccessToken); $ ResData = $ this-> cUrlRequest ($ url, '{"status ":'. $ state. '}'); // echo"
"; Print_r (json_decode ($ ResData);} // you can specify the public function sLogisticsList () {$ this-> Logistics ['fsearch _ Code'] = "postal EMS"; $ this-> Logistics ['002shentong '] = "STO "; $ this-> Logistics ['066zhongtong'] = "Zhongtong Express"; $ this-> Logistics ['056yuw.g'] = "Yuantong Express "; $ this-> Logistics ['042tiantian '] = "Daily Express Delivery"; $ this-> Logistics ['003shunfeng'] = "SF Express "; $ this-> Logistics ['059yunda '] = "Yunda Express"; $ this-> Logistics ['064zhaijisong'] = "home delivery "; $ this-> Logistics ['020huitong '] = "Huitong Express"; $ this-> Logistics ['zj001yixun'] = "Yi Xun Express ";} // Obtain the order details public function gOrderInfo ($ order) {$ this-> AccessToken = $ this-> sAcessToken (); // print_r ($ this-> AccessToken ); $ url =" https://api.weixin.qq.com/merchant/order/getbyid?access_token= ". $ This-> AccessToken; $ ResData = $ this-> cUrlRequest ($ url, '{"order_id ":"'. $ order. '"}'); // $ url =" https://api.weixin.qq.com/merchant/order/getbyfilter?access_token= ". $ This-> AccessToken; // $ ResData = $ this-> cUrlRequest ($ url, '{"status": 2 }'); print_r (json_decode ($ ResData);} // query all orders public function gOrderAll ($ data = array ()) {$ this-> AccessToken = $ this-> sAcessToken (); $ url =" https://api.weixin.qq.com/merchant/order/getbyfilter?access_token= ". $ This-> AccessToken; if (! Empty ($ data) {$ data = json_encode ($ data);} else {$ firstday = strtotime (date ("Y-m-01", time ())); $ data = array ('begintime' => $ firstday, 'endtime' => strtotime ("$ firstday + 1 month-1 day ")); $ data = json_encode ($ data) ;}$ ResData =$ this-> cUrlRequest ($ url, $ data); print_r (json_decode ($ ResData ));} // set the order shipping public function sOrderDelivery ($ data = array ("need_delivery" => '0') {$ this-> AccessToken = $ this-> sAcessToken (); $ url =" https://api.weixin.qq.com/merchant/order/setdelivery?access_token= ". $ This-> AccessToken; if (! Empty ($ data) {$ data = json_encode ($ data);} else {$ data = array ("need_delivery" => '0 '); $ data = json_encode ($ data) ;}$ ResData =$ this-> cUrlRequest ($ url, $ data); print_r (json_decode ($ ResData ));} // close the order public function sOrderClose ($ order) {$ this-> AccessToken = $ this-> sAcessToken (); $ url =" https://api.weixin.qq.com/merchant/order/close?access_token= ". $ This-> AccessToken; $ ResData = $ this-> cUrlRequest ($ url, '{"order_id ":"'. $ order. '"}'); print_r (json_decode ($ ResData ));}}

2. code execution on the page

   "; // Query all Products $ wXd-> gStateProduct (); // Obtain Order information $ wXd-> gOrderInfo ('20140901 '); // close the order $ wXd-> sOrderClose ('20140901'); // Set the shipping order $ data ['need _ delivery'] = '1 '; $ data ['Order _ id'] = '000000'; $ data ['delimiter_company '] = '059yunda '; $ data ['delivery _ track_no '] = '000000'; $ wXd-> sOrderDelivery ($ data); // retrieve all orders $ wXd-> gOrderAll (); echo"
";

The above is the content of the second API development and use example for the php version of the store. For more information, please follow the PHP Chinese network (www.php.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.