import { config } from "../config/config" import { wx_pay_data } from "../data/data"; import { log } from "./log" import { tools } from "./tools" import { util } from "./util"; // export default { // onShareAppMessage() { // return { // title: '分享给微信好友', // path: '/pages/bookstore/bookstore' // }; // } // } export class sdkUtil { public static login(cb:Function) { switch (tools.getCurPlatform()){ case config.Platform.H5: cb && cb(null) break case config.Platform.WEIXIN: wx.login({ success(res) { let code = res.code log.Debug("wx_code",code) cb && cb({'code':code}) }, fail(e) { log.Debug(`wx_login 调用失败:`,e) } }) break; case config.Platform.TOUTIAO: tt.login({ force: true, success(res) { let code = res.code let anonymousCode = res.anonymousCode log.Debug("tt_code",code,'tt_anonymousCode',anonymousCode) cb && cb({'code':code,'anonymousCode':anonymousCode}) }, fail(e) { log.Debug(`tt_login 调用失败:`,e) } }); break; default: break; } } public static getIsIosDevice():boolean { let is_ios_device = false switch (tools.getCurPlatform()){ case config.Platform.WEIXIN: let wx_Info = wx.getSystemInfoSync() if(wx_Info.platform == 'ios'){ is_ios_device = true } break; default: break; } return is_ios_device } public static showPayment(data:wx_pay_data,cb:Function){ switch (tools.getCurPlatform()){ case config.Platform.WEIXIN: let wx_Info = wx.getSystemInfoSync() if(wx_Info.platform == 'ios'){ util.showInfoToast("ios 支付!,请调用客服!") }else{ wx.requestPayment({ timeStamp: data.timeStamp, nonceStr: data.nonceStr, package: data.package, paySign: data.paySign, signType:"RSA", success: (res) => { console.log("showPayment - success",res) cb && cb(null,res) }, fail: (res) => { console.log("showPayment - fail",res) cb && cb("fail!",res) }, complete: (res) => { console.log("showPayment - complete",res,data) // cb && cb(res) } }); } break; case config.Platform.TOUTIAO: break; default: cb && cb() break; } } /** * 添加桌面 */ public static addShortcut(cb:Function) { switch (tools.getCurPlatform()){ case config.Platform.WEIXIN: wx.addShortcut({ success() { console.log("添加桌面成功"); cb && cb() }, fail(err) { console.log("添加桌面失败", err.errMsg); }, }); break; case config.Platform.TOUTIAO: tt.addShortcut({ success() { console.log("添加桌面成功"); cb && cb() }, fail(err) { console.log("添加桌面失败", err.errMsg); }, }); break; default: cb && cb() break; } } }