This article describes the PHP version of the micro-letter store interface development method. Share to everyone for your reference, specific as follows:
First of all, you can go to the next small store developed API interface because all of the following micro-letter store interface data format Parameters API manual There are ready-made you can directly use the following code
Here to download the micro-store API documentation
Let's take a look at the merchandise here for example
First, the first step is to get the Access_token code. I did the token here. Because token has restricted private function Access_token () {appid=shopappid;// Copy the AppID when you write your own apps=shop_appsecret;//copy Appsecret write your own wxuserdb=m (' wxuser′);//You can get rid of this here and notice!!!
Wxuser=wxuserdb−>where (Array (' Appid′=>appid))->find (); Get Access_token if (wxuser[′atupdatetime′]==′′| | Intval (Time ()) −intval (wxuser[' atupdatetime ') >4000| | $wxuser [' Access_token ']== '] {$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential& Appid= ". $appid."
&secret= ". $apps;
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_ssl_verifypeer, FALSE);
curl_setopt ($ch, Curlopt_ssl_verifyhost, FALSE);
curl_setopt ($ch, Curlopt_returntransfer, 1);
$output = curl_exec ($ch);
Curl_close ($ch);
$jsoninfo = Json_decode ($output, true);
$access _token = $jsoninfo ["Access_token"];
$wxuser [' Access_token ']= $access _token;
$wxuser [' Atupdatetime ']=time (); $wxuserdb->where Array (' AppID' => $appid))->save ($wxuser);
}else{$access _token = $wxuser [' Access_token '];
return $access _token;
}
Here I encapsulate the data from the interface to get
Encapsulated PHP Curl () method
Private Function Get_res (url,data) {
ch=curlinit (); curlsetopt (ch, curlopt_ssl_verifypeer, FALSE)
; curl_setopt (Ch,curloptsslverifyhost,false); curlsetopt (ch, curlopt_url, URL); curlsetopt (CH, curlopt_postfields, data); curlsetopt (CH, curlopt_returntransfer, true);
Output=curlexec (CH);
Curl_close (ch); jsoninfo = Json_decode (output,true); returnjsoninfo;
}
/**
* ProductID get ProductInfo obtain merchandise information based on ID *
*
Private Function Get_product_info () {
wxtoken=this- >access_token ()//Get to token
productid=′pp3k2s25zdry50n3nlckqzvpzinm′;//commodity idurl = "https:// Api.weixin.qq.com/merchant/get?access_token= ". wxtoken;//here is the interface address data= ' {' product_id ':" '. product_id. ' ", via commodity ID. ';
Echothis->get_res (url,data);//exit via the previously encapsulated PHP Curl () method
;
Friends that need to be used directly only need to change AppID and secret
Other interfaces only need to replace the interface address and the transmitted data
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.