sdkUtil.ts 2.9 KB

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