pay.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import 'dart:async';
  2. import 'package:alipay_kit/alipay_kit.dart';
  3. import 'package:bot_toast/bot_toast.dart';
  4. import 'package:fluwx/fluwx.dart';
  5. import 'package:twong/config/pay_config.dart';
  6. import 'package:twong/models/details.dart';
  7. // import 'package:wechat_kit/wechat_kit.dart';
  8. import 'index.dart';
  9. class Pay {
  10. static init() {
  11. _alipay.payResp().listen(_listenAliPay);
  12. // _wechat.registerApp(appId: PayConfig.wechatAppId,
  13. // universalLink: PayConfig.universalLink);
  14. // _wechat.payResp().listen(_listenWechatPay);
  15. // _wechat.shareMsgResp().listen(_listenWechatShare);
  16. _alipay.isInstalled().then((value) {
  17. _aliInstalled = value;
  18. Log.d("检查完毕 支付宝${value ? '已安装' : '未安装'}");
  19. });
  20. // _wechat.isInstalled().then((value) {
  21. // _weInstalled = value;
  22. // Log.d("检查完毕 微信${value ? '已安装' : '未安装'}");
  23. // });
  24. registerWxApi(appId: PayConfig.wechatAppId, universalLink: PayConfig.universalLink);
  25. }
  26. static Alipay _alipay = Alipay();
  27. // static Wechat _wechat = Wechat();
  28. static bool _weInstalled = false;
  29. static bool _aliInstalled = false;
  30. // Alipay get alipay => _alipay;
  31. // Wechat get wechat => _wechat;
  32. static Function(bool) _callback;
  33. static void _listenAliPay(AlipayResp resp) {
  34. Log.d('Alipay : ${resp.resultStatus} - ${resp.result} ${resp.memo}');
  35. if(_callback != null) {
  36. // _callback(resp.resultStatus == Alipay);
  37. _callback(false);
  38. }
  39. }
  40. // static void _listenWechatPay(WechatPayResp resp) {
  41. // Log.d('WechatPay : ${resp.returnKey} - ${resp.errorCode}: ${resp.errorMsg}');
  42. // if(_callback != null) {
  43. // _callback(resp.errorCode == WechatSdkResp.ERRORCODE_SUCCESS);
  44. // _callback = null;
  45. // }
  46. // }
  47. //
  48. // static void _listenWechatShare(WechatSdkResp resp) {
  49. // Log.d('WechatShare : ${resp.errorCode}: ${resp.errorMsg}');
  50. // if(_callback != null) {
  51. // _callback(resp.errorCode == WechatSdkResp.ERRORCODE_SUCCESS);
  52. // _callback = null;
  53. // }
  54. // }
  55. static void aliPay(String conf, {Function(bool) callback}) {
  56. if(!_aliInstalled) {
  57. BotToast.showText(text: "没有安装支付宝");
  58. return;
  59. }
  60. _callback = callback;
  61. Log.d("begin alipay ...");
  62. _alipay.payOrderSign(orderInfo: conf);
  63. }
  64. static void wechatPay(dynamic payConf, {Function(bool) callback}) {
  65. // if (!_weInstalled) {
  66. // BotToast.showText(text: "没有安装微信");
  67. // return;
  68. // }
  69. Log.d("begin wechat pay ...");
  70. payWithWeChat(appId: payConf["appid"],
  71. partnerId: payConf["partnerid"],
  72. prepayId: payConf["prepayid"],
  73. packageValue: payConf["package"],
  74. nonceStr: payConf["noncestr"],
  75. timeStamp: payConf["timestamp"],
  76. sign: payConf["sign"]).then((value) {
  77. if(callback != null) {
  78. callback(value);
  79. }
  80. });
  81. // _callback = callback;
  82. // _wechat.pay(appId: payConf["appid"],
  83. // partnerId: payConf["partnerid"],
  84. // prepayId: payConf["prepayid"],
  85. // package: payConf["package"],
  86. // nonceStr: payConf["noncestr"],
  87. // timeStamp: payConf["timestamp"].toString(),
  88. // sign: payConf["sign"]);
  89. }
  90. static void wechatShare(bool friend, Details data, {Function(bool) callback}) {
  91. // if(!_weInstalled) {
  92. // BotToast.showText(text: "没有安装微信");
  93. // return;
  94. // }
  95. Log.d("begin share ...");
  96. // _wechat.shareWebpage(
  97. // scene: friend ? WechatScene.SESSION : WechatScene.TIMELINE,
  98. // webpageUrl: "https://twong.shotshock.shop/share${data.storeInfo.id}",
  99. // title: data.storeInfo.store_name,
  100. // description: data.storeInfo.store_info);
  101. shareToWeChat(WeChatShareWebPageModel(
  102. "https://twong.shotshock.shop/mobilex/share?id=${data.storeInfo.id}",
  103. title: data.storeInfo.store_name,
  104. description: data.storeInfo.store_info,
  105. thumbnail: WeChatImage.network(data.storeInfo.image),
  106. scene: friend ? WeChatScene.SESSION : WeChatScene.TIMELINE,
  107. )).then((value) {
  108. if(callback != null) {
  109. callback(value);
  110. }
  111. });
  112. }
  113. }