PHP version of WeChat store interface development instance, php store interface instance

Source: Internet
Author: User
Tags api manual

PHP version store interface development instance, php store interface instance

This article describes how to develop a PHP store interface. We will share this with you for your reference. The details are as follows:

First, you can go to the next store to develop the API interface because all the store interface data format parameters in the API manual are ready for use. You can use the following code directly.

Here we will download the mini store API documentation

Here we will take the commodity query as an example.

// The first step is to obtain the code for access_token. Here I have saved the token in the table because the token has a limit on private function access_token () {appid = shopappid; // write the appid to your own apps = shop_appsecret during replication; // write the appsecret to your own wxuserdb = M ('wxuser') during replication ′); // you can remove this note !!! Wxuser = wxuserdb −> where (array ('appid '=> appid)-> find (); // obtain access_tokenif (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, expires, 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 ['updatetime'] = time (); $ wxuserdb-> where (array ('appid '=> $ appid)-> save ($ wxuser );} else {$ access_token = $ wxuser ['Access _ token'];} return $ access_token ;}

Here I encapsulate the following to get data through the interface

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 get Product Information Based on id */private function get_product_info () {wxtoken = this-> access_token (); // get tokenproductid = 'pP3K2s25zDRY50n3nLCKqZvPzINM ′; // item idurl = "https://api.weixin.qq.com/merchant/get? Access_token = ". wxtoken; // The API address data = '{"product_id ":"'. product_id. '"}'; echothis-> get_res (url, data); // exit using the previously encapsulated PHP curl () method ;}

You only need to change the appid and secret.

For other interfaces, you only need to replace the interface address and transmitted data.

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.