sdkUtil.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { config } from "../config/config"
  2. import { wx_pay_data } from "../data/data";
  3. import { log } from "./log"
  4. import { tools } from "./tools"
  5. import { util } from "./util";
  6. // export default {
  7. // onShareAppMessage() {
  8. // return {
  9. // title: '分享给微信好友',
  10. // path: '/pages/bookstore/bookstore'
  11. // };
  12. // }
  13. // }
  14. export class sdkUtil {
  15. public static login(cb:Function) {
  16. switch (tools.getCurPlatform()){
  17. case config.Platform.H5:
  18. cb && cb(null)
  19. break
  20. case config.Platform.WEIXIN:
  21. wx.login({
  22. success(res) {
  23. let code = res.code
  24. log.Debug("wx_code",code)
  25. cb && cb({'code':code})
  26. },
  27. fail(e) { log.Debug(`wx_login 调用失败:`,e) }
  28. })
  29. break;
  30. case config.Platform.TOUTIAO:
  31. tt.login({
  32. force: true,
  33. success(res) {
  34. let code = res.code
  35. let anonymousCode = res.anonymousCode
  36. log.Debug("tt_code",code,'tt_anonymousCode',anonymousCode)
  37. cb && cb({'code':code,'anonymousCode':anonymousCode})
  38. },
  39. fail(e) { log.Debug(`tt_login 调用失败:`,e) }
  40. });
  41. break;
  42. default:
  43. break;
  44. }
  45. }
  46. public static showPayment(data:wx_pay_data,cb:Function){
  47. switch (tools.getCurPlatform()){
  48. case config.Platform.WEIXIN:
  49. let wx_Info = wx.getSystemInfoSync()
  50. if(wx_Info.platform == 'ios'){
  51. util.showInfoToast("ios 支付!,请调用客服!")
  52. }else{
  53. wx.requestPayment({
  54. timeStamp: data.timeStamp,
  55. nonceStr: data.nonceStr,
  56. package: data.package,
  57. paySign: data.paySign,
  58. signType:"RSA",
  59. success: (res) => {
  60. console.log("showPayment - success",res)
  61. cb && cb(null,res)
  62. },
  63. fail: (res) => {
  64. console.log("showPayment - fail",res)
  65. cb && cb("fail!",res)
  66. },
  67. complete: (res) => {
  68. console.log("showPayment - complete",res,data)
  69. // cb && cb(res)
  70. }
  71. });
  72. }
  73. break;
  74. case config.Platform.TOUTIAO:
  75. break;
  76. default:
  77. cb && cb()
  78. break;
  79. }
  80. }
  81. /**
  82. * 添加桌面
  83. */
  84. public static addShortcut(cb:Function) {
  85. switch (tools.getCurPlatform()){
  86. case config.Platform.WEIXIN:
  87. wx.addShortcut({
  88. success() {
  89. console.log("添加桌面成功");
  90. cb && cb()
  91. },
  92. fail(err) {
  93. console.log("添加桌面失败", err.errMsg);
  94. },
  95. });
  96. break;
  97. case config.Platform.TOUTIAO:
  98. tt.addShortcut({
  99. success() {
  100. console.log("添加桌面成功");
  101. cb && cb()
  102. },
  103. fail(err) {
  104. console.log("添加桌面失败", err.errMsg);
  105. },
  106. });
  107. break;
  108. default:
  109. cb && cb()
  110. break;
  111. }
  112. }
  113. }