|
|
@@ -0,0 +1,97 @@
|
|
|
+var wechat_installed = false;
|
|
|
+
|
|
|
+const WeChat = {
|
|
|
+ init: function() {
|
|
|
+ try {
|
|
|
+ this.checkInstall();
|
|
|
+ } catch {
|
|
|
+ console.log("Wechat is undefined !");
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ checkInstall: function() {
|
|
|
+ Wechat.isInstalled(
|
|
|
+ function(installed) {
|
|
|
+ wechat_installed = installed;
|
|
|
+ console.log("Wechat installed: " + (installed ? "Yes" : "No"));
|
|
|
+ },
|
|
|
+ function(reason) {
|
|
|
+ wechat_installed = false;
|
|
|
+ console.log("Failed: " + reason);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ },
|
|
|
+
|
|
|
+ shareText: function(text, callback, type) {
|
|
|
+ if (!wechat_installed) return;
|
|
|
+
|
|
|
+ if (type == undefined) type = Wechat.Scene.SESSION;
|
|
|
+ else type = Wechat.Scene.TIMELINE;
|
|
|
+
|
|
|
+ Wechat.share(
|
|
|
+ {
|
|
|
+ text: text,
|
|
|
+ scene: type
|
|
|
+ },
|
|
|
+ function() {
|
|
|
+ callback(true);
|
|
|
+ },
|
|
|
+ function(reason) {
|
|
|
+ callback(false, reason);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ },
|
|
|
+
|
|
|
+ // title: "这是分享的标题",
|
|
|
+ // description: "这是分享的描述",
|
|
|
+ // thumb: "www/assets/imgs/logo.png",
|
|
|
+ // media: {
|
|
|
+ // type: Wechat.Type.WEBPAGE,
|
|
|
+ // webpageUrl: "https://www.jason-z.com"
|
|
|
+ // }
|
|
|
+ shareLink: function(message, callback, type) {
|
|
|
+ if (!wechat_installed) return;
|
|
|
+
|
|
|
+ if (type == undefined) type = Wechat.Scene.SESSION;
|
|
|
+ else type = Wechat.Scene.TIMELINE;
|
|
|
+
|
|
|
+ Wechat.share(
|
|
|
+ {
|
|
|
+ message: message,
|
|
|
+ scene: type
|
|
|
+ },
|
|
|
+ function() {
|
|
|
+ callback(true);
|
|
|
+ },
|
|
|
+ function(reason) {
|
|
|
+ callback(false, reason);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ },
|
|
|
+
|
|
|
+ // partnerid: '10000100', // merchant id
|
|
|
+ // prepayid: 'wx201411101639507cbf6ffd8b0779950874', // prepay id
|
|
|
+ // noncestr: '1add1a30ac87aa2db72f57a2375d8fec', // nonce
|
|
|
+ // timestamp: '1439531364', // timestamp
|
|
|
+ // sign: '0CB01533B8C1EF103065174F50BCA001', // signed string
|
|
|
+ pay: function(params, callback) {
|
|
|
+ if (!wechat_installed) return;
|
|
|
+ Wechat.sendPaymentRequest(
|
|
|
+ ret.data,
|
|
|
+ function() {
|
|
|
+ callback(true, ret.data);
|
|
|
+ },
|
|
|
+ function(reason) {
|
|
|
+ callback(false, reason);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const Alipay = {
|
|
|
+ init: function() {},
|
|
|
+
|
|
|
+ pay: function() {}
|
|
|
+};
|
|
|
+
|
|
|
+export default WeChat;
|