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