diff --git a/sdk/SDKTools.ts b/sdk/SDKTools.ts index 86eda05..17675f5 100644 --- a/sdk/SDKTools.ts +++ b/sdk/SDKTools.ts @@ -305,6 +305,12 @@ export class SDKTools { static preorder(goodid: string, orderid: string) { return WXSDK.game.preorder(goodid, orderid) } + /** + * 获取商品列表 + */ + static goodslist() { + return WXSDK.game.goodslist() + } /** diff --git a/wxsdk/base/SDKConst.ts b/wxsdk/base/SDKConst.ts index 975f9cf..204ae81 100644 --- a/wxsdk/base/SDKConst.ts +++ b/wxsdk/base/SDKConst.ts @@ -32,10 +32,8 @@ export const GAMEDATA = { } } - - // sdk版本 -export const SDKVersion = 'v1.0.6'; +export const SDKVersion = 'v1.0.7'; // 是否打印 export const __LOG__ = false; // 是否mock @@ -113,6 +111,8 @@ export const HostKeys = { orderReport: 'api/order/v2/mimas', //订单信息上报 orderQuery: 'api/order/query', //订单信息查询 preorder: 'api/order/v2/preorder', //获取支付方式 + // + goodslist: 'api/v2/goodslist', //商品列表 }; // 本地存储keys diff --git a/wxsdk/http/SDKApi.ts b/wxsdk/http/SDKApi.ts index ff6d0ce..3d371a4 100644 --- a/wxsdk/http/SDKApi.ts +++ b/wxsdk/http/SDKApi.ts @@ -75,4 +75,6 @@ export class SDKApi { public static pay = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.orderReport, ...args); public static orderQuery = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.orderQuery, ...args); public static preorder = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.preorder, ...args); + + public static goodslist = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.goodslist, ...args); } diff --git a/wxsdk/http/SDKHttp.ts b/wxsdk/http/SDKHttp.ts index 9184c69..1e4402c 100644 --- a/wxsdk/http/SDKHttp.ts +++ b/wxsdk/http/SDKHttp.ts @@ -2,6 +2,8 @@ import { GAMEDATA, sdkEnv } from "../base/SDKConst"; import SignUtils from "../utils/SignUtils"; export default class SDKHttp { + public static onErrorResponse: (data: any) => void; + public static async httpRequest(url: string, method: string, data?: any, dataType: "json" | "string" = "json") { return new Promise>((resolve, reject) => { data = { @@ -11,12 +13,6 @@ export default class SDKHttp { sign_type: 'md5', time_stamp: (Math.floor(Date.now() / 1000)) + '' } - - // if (url.indexOf('totalrank')>-1) { - // // console.log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") - // url = 'https://wxsdk-game-pre.d3games.com/game/totalrank/list'; - // } - //生成sign data = { ...data, @@ -108,15 +104,25 @@ export default class SDKHttp { } url = baseUrl + url; - return this.httpRequest(url, "GET", data, dataType); + let res = await this.httpRequest(url, "GET", data, dataType); + if (this.onErrorResponse && !res.code) { + // + this.onErrorResponse(res); + } + return res; } - public static httpPost(baseUrl: string, url: string, data?: any, dataType: "json" | "string" = "json") { + public static async httpPost(baseUrl: string, url: string, data?: any, dataType: "json" | "string" = "json") { if (this.withMock(url)) { return this.mockData(url); } url = baseUrl + url; - return this.httpRequest(url, "POST", data, dataType); + let res = await this.httpRequest(url, "POST", data, dataType); + if (this.onErrorResponse && !res.code) { + // + this.onErrorResponse(res); + } + return res } } \ No newline at end of file diff --git a/wxsdk/service/GameService.ts b/wxsdk/service/GameService.ts index bda2027..c237c0d 100644 --- a/wxsdk/service/GameService.ts +++ b/wxsdk/service/GameService.ts @@ -120,6 +120,12 @@ export default class GameService { goodid, orderid }); } + /** + * 商品列表 + */ + goodslist() { + return SDKApi.goodslist(); + } /** * 构建登录/弱登录公用参数 -- libgit2 0.21.0