电商API接口-电商OMS不可或缺的一块 调用代码展示
電商后臺管理系統(tǒng)關(guān)鍵的一環(huán)就是實現(xiàn)電商平臺數(shù)據(jù)的抓取,以及上下架商品、訂單修改等功能的調(diào)用。這里就需要調(diào)用電商API接口。接入電商API接口后再根據(jù)自我的需求進行功能再開發(fā),實現(xiàn)業(yè)務(wù)上的數(shù)字化管理。
其中訂單管理模板上需要用到如下API:
seller_order_list獲取賣出的商品訂單列表
seller_order_detail獲取賣出的商品訂單詳情
seller_order_address獲取賣出的商品訂單地址
seller_order_close賣家關(guān)閉一筆交易
seller_order_message獲取或修改賣出去的訂單備注
seller_order_send訂單發(fā)貨
調(diào)用代碼展示 進入測試
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import java.nio.charset.Charset; import org.json.JSONException; import org.json.JSONObject; import java.io.PrintWriter; import java.net.URLConnection;public class Example {private static String readAll(Reader rd) throws IOException {StringBuilder sb = new StringBuilder();int cp;while ((cp = rd.read()) != -1) {sb.append((char) cp);}return sb.toString();}public static JSONObject postRequestFromUrl(String url, String body) throws IOException, JSONException {URL realUrl = new URL(url);URLConnection conn = realUrl.openConnection();conn.setDoOutput(true);conn.setDoInput(true);PrintWriter out = new PrintWriter(conn.getOutputStream());out.print(body);out.flush();InputStream instream = conn.getInputStream();try {BufferedReader rd = new BufferedReader(new InputStreamReader(instream, Charset.forName("UTF-8")));String jsonText = readAll(rd);JSONObject json = new JSONObject(jsonText);return json;} finally {instream.close();}}public static JSONObject getRequestFromUrl(String url) throws IOException, JSONException {URL realUrl = new URL(url);URLConnection conn = realUrl.openConnection();InputStream instream = conn.getInputStream();try {BufferedReader rd = new BufferedReader(new InputStreamReader(instream, Charset.forName("UTF-8")));String jsonText = readAll(rd);JSONObject json = new JSONObject(jsonText);return json;} finally {instream.close();}}public static void main(String[] args) throws IOException, JSONException {// 請求示例 url 默認(rèn)請求參數(shù)已經(jīng)URL編碼處理String url = "https://api-vx15870092527.cn/taobao/seller_order_list/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&page=&tabCode=&dateBegin=&dateEnd=&buyerNick=&itemTitle=&orderId=&lastStartRow=&detail=&page_size=";JSONObject json = getRequestFromUrl(url);System.out.println(json.toString());}}公共參數(shù)
名稱 | 類型 | 必須 | 描述 |
key | String | 是 | 調(diào)用key(必須以GET方式拼接在URL中) |
secret | String | 是 | 調(diào)用密鑰 |
api_name | String | 是 | API接口名稱(包括在請求地址中)[item_search,item_get,item_search_shop等] |
cache | String | 否 | [yes,no]默認(rèn)yes,將調(diào)用緩存的數(shù)據(jù),速度比較快 |
result_type | String | 否 | [json,jsonu,xml,serialize,var_export]返回數(shù)據(jù)格式,默認(rèn)為json,jsonu輸出的內(nèi)容中文可以直接閱讀 |
lang | String | 否 | [cn,en,ru]翻譯語言,默認(rèn)cn簡體中文 |
version | String | 否 | API版本 |
錯誤碼解釋
狀態(tài)代碼(error_code) | 狀態(tài)信息 | 詳細(xì)描述 | 是否收費 |
0000 | success | 接口調(diào)用成功并返回相關(guān)數(shù)據(jù) | 是 |
2000 | Search success but no result | 接口訪問成功,但是搜索沒有結(jié)果 | 是 |
4000 | Server internal error | 服務(wù)器內(nèi)部錯誤 | 否 |
4001 | Network error | 網(wǎng)絡(luò)錯誤 | 否 |
4002 | Target server error | 目標(biāo)服務(wù)器錯誤 | 否 |
4003 | Param error | 用戶輸入?yún)?shù)錯誤 | 忽略 |
4004 | Account not found | 用戶帳號不存在 | 忽略 |
4005 | Invalid authentication credentials | 授權(quán)失敗 | 忽略 |
4006 | API stopped | 您的當(dāng)前API已停用 | 忽略 |
4007 | Account stopped | 您的賬戶已停用 | 忽略 |
4008 | API rate limit exceeded | 并發(fā)已達(dá)上限 | 忽略 |
4009 | API maintenance | API維護中 | 忽略 |
4010 | API not found with these values | API不存在 | 忽略 |
4012 | Please add api first | 請先添加api | 忽略 |
4013 | Number of calls exceeded | 調(diào)用次數(shù)超限 | 忽略 |
4014 | Missing url param | 參數(shù)缺失 | 忽略 |
4015 | Wrong pageToken | 參數(shù)pageToken有誤 | 忽略 |
4016 | Insufficient balance | 余額不足 | 忽略 |
4017 | timeout error | 請求超時 | 否 |
5000 | unknown error | 未知錯誤 | 否 |
總結(jié)
以上是生活随笔為你收集整理的电商API接口-电商OMS不可或缺的一块 调用代码展示的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用css3动画效果做的跑动效果
- 下一篇: LFS7.4编译笔记(3)