🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
Java示例: https://supply-chain-fs.oss-cn-chengdu.aliyuncs.com/supply-api-demo.zip .Net C# 示例 https://supply-chain-fs.oss-cn-chengdu.aliyuncs.com/DaXiangScmDemo.zip PHP 示例 ``` <?php namespace common\utils; class daxiang_api { public $appid = "346837987331407872";//apiKey public $secret = "801135476cebb8700f45a319d38de308";//apiSecret public $host = "http://api.funengscm.com/"; /** * 获取选品库商品 * @return json */ public function get_goods_shelf_products() { $timestamp = $this->get_msectime(); $post_data['pageNum'] = 1; $post_data['pageSize'] = 50; $post_data = json_encode($post_data); $sign = $this->getSign($post_data,$timestamp); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $this->host."goods-shelf/get-mine-list", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => $post_data, CURLOPT_HTTPHEADER => array( "Content-Type: application/json", "apiKey: ".$this->appid, "cache-control: no-cache", "sign: ".$sign, "timestamp: ".$timestamp ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); return $response; } /** * 获取签名 * @param $post_data * @param bool $timestamp * @return string */ public function getSign($post_data,$timestamp) { $data = [ 'apiKey' => $this->appid, 'body'=>$post_data, 'timestamp' => $timestamp, ]; ksort($data); $signString = ''; foreach($data as $k=>$v){ $signString = $signString."$k=$v&"; } $signString = $signString."secret=$this->secret"; $sign = md5($signString); echo "签名原始串:$signString<br/>"."签名后:$sign <br/>"; return $sign; } //返回当前的毫秒时间戳 public function get_msectime() { list($msec, $sec) = explode(' ', microtime()); $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); return $msectime; } } $apiInvoker = new daxiang_api(); $a = $apiInvoker->get_goods_shelf_products(); echo "<br/> result is:<br/> $a" ?> ``` Python 示例: ``` #需安装:pip install requests import requests import json import hashlib import time #---------------------------以下需要修改--------------------------- apiKey="346837987331407872" apiSecret="801135476cebb8700f45a319d38de308" #--------------------------- END --------------------------- req_data = {"pageNum": 1,"pageSize":5} t=time.time() time_stamp = str(int(round(t * 1000))) url="http://api.funengscm.com/goods-shelf/get-mine-list" dataString = json.dumps(req_data) needSignParams = { 'apiKey':apiKey, 'timestamp':time_stamp, 'body':dataString } needSignParams = dict(sorted(needSignParams.items(),key=lambda x:x[0],reverse=False)) needSignParamsString='' for key,value in needSignParams.items(): needSignParamsString += key +'=' + value+'&' needSignParamsString += 'secret=' + apiSecret md5Sign=hashlib.md5(needSignParamsString.encode(encoding='UTF-8')).hexdigest() print("签名原始串:" + needSignParamsString + "\n" + "签名后:" + md5Sign) headers = { 'Content-Type':'application/json', 'apiKey':apiKey, 'timestamp':time_stamp, 'sign':md5Sign } result = requests.post(url, headers=headers,data=dataString) print("---------------------------result is:---------------------------") print(result.text) ``` golang 示例: ``` package main import ( "crypto/md5" "fmt" "sort" "strconv" "time" "github.com/gogf/gf/frame/g" ) type DxScmConfig struct { ApiKey string ApiSecret string Host string } func NewDxScmConfig(apiKey string, apiSecret string) *DxScmConfig { config := new(DxScmConfig) config.ApiKey = apiKey config.ApiSecret = apiSecret config.Host = "http://api.funengscm.com" return config } var currentConfig *DxScmConfig func setConfig(config *DxScmConfig) { currentConfig = config } type SignParams struct { ApiKey string Timestamp uint64 Sign string } func Invoke(url string, bodyString string) { setConfig(NewDxScmConfig("346837987331407872", "801135476cebb8700f45a319d38de308")) timestamp := strconv.FormatUint(uint64(time.Now().UnixNano()/1e6), 10) needSignParams := g.MapStrStr{ "apiKey": currentConfig.ApiKey, "body": bodyString, "timestamp": timestamp, } keys := make([]string, 0) for k := range needSignParams { keys = append(keys, k) } sort.Strings(keys) var needSignParamsString string = "" for _, k := range keys { needSignParamsString = needSignParamsString + fmt.Sprintf("%s=%s&", k, needSignParams[k]) } needSignParamsString += "secret=" + currentConfig.ApiSecret md5Sign := md5.Sum([]byte(needSignParamsString)) code := fmt.Sprintf("%x", md5Sign) fmt.Println("签名原始串:" + needSignParamsString + "\n" + "签名后:" + code) headers := g.MapStrStr{ "apiKey": currentConfig.ApiKey, "timestamp": timestamp, "sign": code, } response, _ := g.Client().SetHeaderMap(headers).ContentJson().Post(currentConfig.Host+url, bodyString) bodyArray := response.ReadAll() netString := string(bodyArray) fmt.Println(netString) } func GetMyProduct() { bodyString := `{"pageNum": 1,"pageSize":5}` Invoke("/goods-shelf/get-mine-list", bodyString) } func main() { GetMyProduct() } ``` NodeJs ``` const dayjs \= require("dayjs"); const crypto \= require("crypto"); const rp \= require("request-promise"); function objectToUrlParams(obj) { let params \= \[\]; let sortedKeys \= Object.keys(obj).sort(); const sortedObj \= {}; sortedKeys.forEach((key) \=> { sortedObj\[key\] \= obj\[key\]; }); for (let key in sortedObj) { if (sortedObj.hasOwnProperty(key)) { let value \= sortedObj\[key\]; let param \= encodeURIComponent(key) + "=" + value; //encodeURIComponent(value); params.push(param); } } return params.join("&"); } async function apiInvoke(path, method, bodyString) { const host \= "http://api.feisuanyun.com:80"; const apiKey \= "你的apikey"; const apiSecret \= "你的apiSecret"; let uri \= host + path; let timestamp \= dayjs().valueOf(); let needSignParams \= { apiKey: apiKey, timestamp: timestamp, body: bodyString, }; let signSource \= objectToUrlParams(needSignParams) + "&secret=" + apiSecret; console.log(signSource); const sign \= crypto .createHash("md5") .update(signSource) .digest("hex") .toLocaleLowerCase(); const headers \= { "Content-Type": "application/json", apiKey: apiKey, sign: sign, timestamp: timestamp, }; console.log(headers); let result \= await rp({ method: method, uri: uri, //json: true, headers: headers, body: bodyString, }); console.log(result); } async function getUserInfo() { apiInvoke("/user/get-user-info", "GET", ""); } async function changePwd() { let bodyJson \= { oldPassword: "123", password: "456" }; let bodyString \= JSON.stringify(bodyJson); console.log(bodyString); apiInvoke("/user/update-password-json", "POST", bodyString); } async function changeNodeName() { let bodyJson \= { id: "574147754469621760", name: "test-123" }; let bodyString \= JSON.stringify(bodyJson); console.log(bodyString); apiInvoke("/node/update-node-name", "POST", bodyString); } //getUserInfo(); //changePwd(); changeNodeName(); ```