pay.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. var wechat_installed = false;
  2. const WeChat = {
  3. init: function() {
  4. try {
  5. this.checkInstall();
  6. } catch {
  7. console.log("Wechat is undefined !");
  8. }
  9. },
  10. checkInstall: function() {
  11. Wechat.isInstalled(
  12. function(installed) {
  13. wechat_installed = installed;
  14. console.log("Wechat installed: " + (installed ? "Yes" : "No"));
  15. },
  16. function(reason) {
  17. wechat_installed = false;
  18. console.log("Failed: " + reason);
  19. }
  20. );
  21. },
  22. shareText: function(text, callback, type) {
  23. if (!wechat_installed) return;
  24. if (type == undefined) type = Wechat.Scene.SESSION;
  25. else type = Wechat.Scene.TIMELINE;
  26. Wechat.share(
  27. {
  28. text: text,
  29. scene: type
  30. },
  31. function() {
  32. callback(true);
  33. },
  34. function(reason) {
  35. callback(false, reason);
  36. }
  37. );
  38. },
  39. // title: "这是分享的标题",
  40. // description: "这是分享的描述",
  41. // thumb: "www/assets/imgs/logo.png",
  42. // media: {
  43. // type: Wechat.Type.WEBPAGE,
  44. // webpageUrl: "https://www.jason-z.com"
  45. // }
  46. shareLink: function(message, callback, type) {
  47. if (!wechat_installed) return;
  48. if (type == undefined) type = Wechat.Scene.SESSION;
  49. else type = Wechat.Scene.TIMELINE;
  50. Wechat.share(
  51. {
  52. message: message,
  53. scene: type
  54. },
  55. function() {
  56. callback(true);
  57. },
  58. function(reason) {
  59. callback(false, reason);
  60. }
  61. );
  62. },
  63. // partnerid: '10000100', // merchant id
  64. // prepayid: 'wx201411101639507cbf6ffd8b0779950874', // prepay id
  65. // noncestr: '1add1a30ac87aa2db72f57a2375d8fec', // nonce
  66. // timestamp: '1439531364', // timestamp
  67. // sign: '0CB01533B8C1EF103065174F50BCA001', // signed string
  68. pay: function(params, callback) {
  69. if (!wechat_installed) return;
  70. Wechat.sendPaymentRequest(
  71. ret.data,
  72. function() {
  73. callback(true, ret.data);
  74. },
  75. function(reason) {
  76. callback(false, reason);
  77. }
  78. );
  79. }
  80. };
  81. const Alipay = {
  82. init: function() {},
  83. pay: function() {}
  84. };
  85. export default WeChat;