php版微信小店調(diào)用api示例代碼
本文實(shí)例講述了php版微信小店調(diào)用api的方法。分享給大家供大家參考,具體如下:
剛開(kāi)始調(diào)用微信小店api的時(shí)候,可能大家會(huì)遇到問(wèn)題。系統(tǒng)總是提示system error,歸根結(jié)底還是發(fā)送的參數(shù)不正確。
下面給出幾個(gè)調(diào)用例子:
例子寫(xiě)得不全。
<?php 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; } //獲取所有商品 function gStateProduct($state = 0,$token){ //https://api.weixin.qq.com/merchant/getbystatus?access_token=ACCESS_TOKEN //{"status": 0} // $AccessToken = "xxxxxxxx"; $url = "https://api.weixin.qq.com/merchant/getbystatus?access_token=".$token; //print_r($this->AccessToken); $ResData = cUrlRequest($url,'{"status": '.$state.'}'); //特別注意這里,這個(gè)是json格式的。 echo "<pre>"; print_r( json_decode($ResData) ); } //獲得所有分組 function getAllCategory($state = 0,$token) { $url = "https://api.weixin.qq.com/merchant/group/getall?access_token=".$token; $ResData = cUrlRequest($url,'{"status": '.$state.'}'); echo "<pre>"; print_r( json_decode($ResData) ); } //根據(jù)分組id來(lái)獲得商品信息 function getProductByGroudid($state = 0,$token) { $url = "https://api.weixin.qq.com/merchant/group/getbyid?access_token=".$token; $ResData = cUrlRequest($url,'{"group_id": '.$state.'}'); echo "<pre>"; print_r( json_decode($ResData) ); } //獲取accesstoken function getAccessToken() { $appid = "your appid"; $appsecret = "your appsecret"; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret; $result = cUrlRequest($url); $jsoninfo = json_decode($result, true); $access_token = $jsoninfo["access_token"]; return $access_token; } //根據(jù)product_id來(lái)獲取單個(gè)商品 function getOneProductByid($state = 0,$token) { $url="https://api.weixin.qq.com/merchant/get?access_token=".$token; $ResData = cUrlRequest($url,'{"product_id": "'.$state.'""}'); echo "<pre>"; print_r( json_decode($ResData) ); } $AccessToken=getAccessToken(); //gStateProduct(1,$AccessToken); //getAllCategory(1,$AccessToken); //getProductByGroudid(207061749,$AccessToken); getOneProductByid("pf82VwN45zr8eOlur5mAiSTjg8WU",$AccessToken);
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《PHP微信開(kāi)發(fā)技巧匯總》、《PHP編碼與轉(zhuǎn)碼操作技巧匯總》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語(yǔ)法入門(mén)教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
- php版微信小店API二次開(kāi)發(fā)及使用示例
- PHP版微信小店接口開(kāi)發(fā)實(shí)例
- php版微信公眾號(hào)接口實(shí)現(xiàn)發(fā)紅包的方法
- PHP版微信第三方實(shí)現(xiàn)一鍵登錄及獲取用戶(hù)信息的方法
- php版微信開(kāi)發(fā)之接收消息,自動(dòng)判斷及回復(fù)相應(yīng)消息的方法
- php版微信公眾平臺(tái)之微信網(wǎng)頁(yè)登陸授權(quán)示例
- php版微信公眾號(hào)自定義分享內(nèi)容實(shí)現(xiàn)方法
- php版微信公眾平臺(tái)回復(fù)中文出現(xiàn)亂碼問(wèn)題的解決方法
- 微信支付掃碼支付php版
- PHP版微信公眾平臺(tái)紅包API
- php版微信返回用戶(hù)text輸入的方法
相關(guān)文章
PHP json格式和js json格式 js跨域調(diào)用實(shí)現(xiàn)代碼
整理一個(gè)json格式的例子,以及php json格式與js json之間的調(diào)用(傳說(shuō)中的js跨域調(diào)用)2012-09-09利用PHP函數(shù)計(jì)算中英文字符串長(zhǎng)度的方法
這篇文章主要介紹了利用PHP函數(shù)計(jì)算中英文字符串長(zhǎng)度的方法,實(shí)例對(duì)比了PHP函數(shù)實(shí)現(xiàn)方法與正則表達(dá)式的實(shí)現(xiàn)方法,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-11-11PHP大文件及斷點(diǎn)續(xù)傳下載實(shí)現(xiàn)代碼
這篇文章主要介紹了PHP大文件及斷點(diǎn)續(xù)傳下載實(shí)現(xiàn)代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08php中模擬POST傳遞數(shù)據(jù)的兩種方法分享
php中模擬POST傳遞數(shù)據(jù)的兩種方法分享,有時(shí)候需要模擬提交數(shù)據(jù)方便采集,需要的朋友可以參考下。2011-09-09PHP中通過(guò)ADODB庫(kù)實(shí)現(xiàn)調(diào)用Access數(shù)據(jù)庫(kù)之修正版本
PHP中通過(guò)ADODB庫(kù)實(shí)現(xiàn)調(diào)用Access數(shù)據(jù)庫(kù)之修正版本...2006-12-12