This article describes the PHP version of the micro-letter store API two times development and use methods. Share to everyone for your reference, specific as follows:
1. weixiaodian.php page:
<?php class WxD {public $AppID = "";
Public $AppSecret = "";
Public $OutPut = "";
Public $AccessToken = "";
Public $ID = "";
Public $HandleAT = Array ();
Public $Logistics = Array ();
Public function __construct ($ID = ' 0 ') {$this->id = $ID;
$this->slogisticslist ();
The 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, Curlopt_returntransfer, 1);
$output = curl_exec ($curl);
Curl_close ($curl);
return $output;
}//Get Accesstoken Public Function Sacesstoken () {$this->handleat = $this->gaccesstoken (); if ($this->handleat->expire_time < TiMe ()) {$appid = $this->appid;
$appsecret = $this->appsecret; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=". $appid. "
&secret= ". $appsecret;
$result = Https_request ($url); Echo ' <pre> ';
Var_dump ($result);d ie;
$jsoninfo = Json_decode ($result, true);
$access _token = $jsoninfo ["Access_token"];
$this->paccesstoken ($access _token);
return $access _token;
else{return $this->handleat->access_token; }//Save 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; //Get all Merchandise public Function gstateproduct ($state = 0) {//https://api.weixin.qq.com/merchant/getbystatus?acce
Ss_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 "<pre>";
Print_r (Json_decode ($ResData)); //Set up the Mini Store logistics Support list public Function slogisticslist () {$this->logistics[' FsearcH_code '] = "Postal EMS";
$this->logistics[' 002shentong '] = "Shentong Express";
$this->logistics[' 066zhongtong '] = "Zhong Tong Express";
$this->logistics[' 056yuantong '] = "Yuantong Express";
$this->logistics[' 042tiantian '] = "Daily Express";
$this->logistics[' 003shunfeng '] = "shun Fung fast Transport";
$this->logistics[' 059Yunda '] = "Yun da Express";
$this->logistics[' 064zhaijisong '] = "house urgent send";
$this->logistics[' 020huitong '] = "Huitong Express";
$this->logistics[' Zj001yixun '] = "Ishun Express";
//Get 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 order 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 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" =&Gt
' 0 ');
$data = Json_encode ($data);
$ResData = $this->curlrequest ($url, $data);
Print_r (Json_decode ($ResData));
//Close 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. Page execution Code
<?php
include_once ' class/weixiaodian.php ';
$wXd = new WxD ();
echo "<pre>";
Search All Merchandise
$wXd->gstateproduct ();
Get order Information
$wXd->gorderinfo (' 12963133879983601645 ');
Close Order
$wXd->sorderclose (' 12963133879983600740 ');
Shipping order Set
$data [' need_delivery '] = ' 1 ';
$data [' order_id '] = ' 12963133879983600667 ';
$data [' delivery_company '] = ' 059Yunda ';
$data [' delivery_track_no '] = ' 1000464090326 ';
$wXd->sorderdelivery ($data);
Get all orders
$wXd->gorderall ();
echo "</pre>";
For more information on PHP related content readers can view the site topics: "PHP micro-credit Development Skills summary", "PHP coding and transcoding Operation skills Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP string (String) Usage Summary", "php+ MySQL Database operations Introduction tutorial and PHP Common database operation Skills Summary
I hope this article will help you with the PHP program design.