sdkUtil.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 getIsIosDevice():boolean {
  47. let is_ios_device = false
  48. switch (tools.getCurPlatform()){
  49. case config.Platform.WEIXIN:
  50. let wx_Info = wx.getSystemInfoSync()
  51. if(wx_Info.platform == 'ios'){
  52. is_ios_device = true
  53. }
  54. break;
  55. default:
  56. break;
  57. }
  58. return is_ios_device
  59. }
  60. public static showPayment(data:wx_pay_data,cb:Function){
  61. switch (tools.getCurPlatform()){
  62. case config.Platform.WEIXIN:
  63. // let wx_Info = wx.getSystemInfoSync()
  64. // if(wx_Info.platform == 'ios'){
  65. // util.showInfoToast("ios 支付!,请调用客服!")
  66. // }else{
  67. wx.requestPayment({
  68. timeStamp: data.timeStamp,
  69. nonceStr: data.nonceStr,
  70. package: data.package,
  71. paySign: data.paySign,
  72. signType:"RSA",
  73. success: (res) => {
  74. console.log("showPayment - success",res)
  75. cb && cb(null,res)
  76. },
  77. fail: (res) => {
  78. console.log("showPayment - fail",res)
  79. cb && cb("fail!",res)
  80. },
  81. complete: (res) => {
  82. console.log("showPayment - complete",res,data)
  83. // cb && cb(res)
  84. }
  85. });
  86. // }
  87. break;
  88. case config.Platform.TOUTIAO:
  89. break;
  90. default:
  91. cb && cb()
  92. break;
  93. }
  94. }
  95. /**
  96. * 添加桌面
  97. */
  98. public static addShortcut(cb:Function) {
  99. switch (tools.getCurPlatform()){
  100. case config.Platform.WEIXIN:
  101. wx.addShortcut({
  102. success() {
  103. console.log("添加桌面成功");
  104. cb && cb()
  105. },
  106. fail(err) {
  107. console.log("添加桌面失败", err.errMsg);
  108. },
  109. });
  110. break;
  111. case config.Platform.TOUTIAO:
  112. tt.addShortcut({
  113. success() {
  114. console.log("添加桌面成功");
  115. cb && cb()
  116. },
  117. fail(err) {
  118. console.log("添加桌面失败", err.errMsg);
  119. },
  120. });
  121. break;
  122. default:
  123. cb && cb()
  124. break;
  125. }
  126. }
  127. }