From: guangchao.xu Date: Wed, 8 Jul 2020 09:55:24 +0000 (+0800) Subject: 添加微信分分享按钮 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=b7b1cd7147edc554dd1efd4c4bf6ef84d934efa1;p=dali_platform%2Fmobile.git 添加微信分分享按钮 --- diff --git a/package-lock.json b/package-lock.json index ad363bc..d50bafb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -370,6 +370,20 @@ "resolved": "https://registry.npmjs.org/cordova-plugin-touch-id/-/cordova-plugin-touch-id-3.4.0.tgz", "integrity": "sha512-2rHwAngECGcIiYCSGDtduwisGCcmGbV++fMfOuoiXLdc0hd6uj9kmR3EWBtKF2/q4erZnl+5+u+0tFIFSprGzA==" }, + "cordova-plugin-wechat": { + "version": "git+https://github.com/xu-li/cordova-plugin-wechat.git#82f4fbc259ea7371eed2eff57645b29fd76af718", + "from": "git+https://github.com/xu-li/cordova-plugin-wechat.git", + "requires": { + "shelljs": "^0.5.3" + }, + "dependencies": { + "shelljs": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.5.3.tgz", + "integrity": "sha1-xUmCuZbHbvDB5rWfvcWCX1txMRM=" + } + } + }, "cordova-plugin-whitelist": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/cordova-plugin-whitelist/-/cordova-plugin-whitelist-1.3.3.tgz", diff --git a/package.json b/package.json index f844329..8de6f24 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "cordova-plugin-statusbar": "^2.4.2", "cordova-plugin-themeablebrowser": "^0.2.18", "cordova-plugin-touch-id": "^3.4.0", + "cordova-plugin-wechat": "git+https://github.com/xu-li/cordova-plugin-wechat.git", "cordova-plugin-wkwebview-engine": "^1.2.1", "jpush-phonegap-plugin": "^3.7.2", "shelljs": "^0.8.3" @@ -64,6 +65,10 @@ "cordova-plugin-prevent-screenshot-coffice": {}, "cordova-plugin-qqsdk": { "QQ_APP_ID": "101885581" + }, + "cordova-plugin-wechat": { + "WECHATAPPID": "wxa483e2c392b08993", + "UNIVERSALLINK": "YOUR_UNIVERSAL_LINK" } }, "platforms": [ diff --git a/platforms/android/android.json b/platforms/android/android.json index 105b5f2..02e24ed 100644 --- a/platforms/android/android.json +++ b/platforms/android/android.json @@ -107,6 +107,14 @@ { "xml": "", "count": 1 + }, + { + "xml": "", + "count": 1 + }, + { + "xml": "", + "count": 1 } ] } @@ -116,7 +124,7 @@ "/*": [ { "xml": "", - "count": 2 + "count": 3 }, { "xml": "", @@ -137,6 +145,22 @@ { "xml": "", "count": 1 + }, + { + "xml": "", + "count": 1 + }, + { + "xml": "", + "count": 1 + }, + { + "xml": "", + "count": 1 + }, + { + "xml": "", + "count": 1 } ], "/manifest": [ @@ -283,6 +307,14 @@ { "xml": "", "count": 1 + }, + { + "xml": "", + "count": 1 + }, + { + "xml": "", + "count": 1 } ] } @@ -401,6 +433,11 @@ "cordova-plugin-qqsdk": { "QQ_APP_ID": "101885581", "PACKAGE_NAME": "com.dalipolice.app" + }, + "cordova-plugin-wechat": { + "WECHATAPPID": "wxa483e2c392b08993", + "UNIVERSALLINK": "YOUR_UNIVERSAL_LINK", + "PACKAGE_NAME": "com.dalipolice.app" } }, "dependent_plugins": {}, @@ -764,6 +801,14 @@ "clobbers": [ "QQSDK" ] + }, + { + "id": "cordova-plugin-wechat.Wechat", + "file": "plugins/cordova-plugin-wechat/www/wechat.js", + "pluginId": "cordova-plugin-wechat", + "clobbers": [ + "Wechat" + ] } ], "plugin_metadata": { @@ -786,6 +831,7 @@ "cordova-plugin-brightness": "0.1.5", "cordova-plugin-fingerprint-aio": "3.0.1", "cordova-plugin-prevent-screenshot-coffice": "1.0.1", - "cordova-plugin-qqsdk": "0.9.7" + "cordova-plugin-qqsdk": "0.9.7", + "cordova-plugin-wechat": "3.0.0" } } diff --git a/platforms/android/app/build.gradle b/platforms/android/app/build.gradle index e758e33..6a72223 100644 --- a/platforms/android/app/build.gradle +++ b/platforms/android/app/build.gradle @@ -92,6 +92,7 @@ ext { // PLUGIN GRADLE EXTENSIONS START apply from: "../cordova-plugin-qrscanner/dlapp-qrscanner.gradle" apply from: "../cordova-plugin-fingerprint-aio/app-build.gradle" +apply from: "../cordova-plugin-wechat/app-android-build.gradle" // PLUGIN GRADLE EXTENSIONS END def hasBuildExtras1 = file('build-extras.gradle').exists() diff --git a/platforms/android/app/src/main/AndroidManifest.xml b/platforms/android/app/src/main/AndroidManifest.xml index 4b6fab6..7ccac86 100644 --- a/platforms/android/app/src/main/AndroidManifest.xml +++ b/platforms/android/app/src/main/AndroidManifest.xml @@ -90,6 +90,20 @@ + + + + + + + + + + + + + + diff --git a/platforms/android/app/src/main/assets/www/cordova_plugins.js b/platforms/android/app/src/main/assets/www/cordova_plugins.js index 08297e5..02af8e9 100644 --- a/platforms/android/app/src/main/assets/www/cordova_plugins.js +++ b/platforms/android/app/src/main/assets/www/cordova_plugins.js @@ -359,6 +359,14 @@ cordova.define('cordova/plugin_list', function(require, exports, module) { "clobbers": [ "QQSDK" ] + }, + { + "id": "cordova-plugin-wechat.Wechat", + "file": "plugins/cordova-plugin-wechat/www/wechat.js", + "pluginId": "cordova-plugin-wechat", + "clobbers": [ + "Wechat" + ] } ]; module.exports.metadata = { @@ -381,6 +389,7 @@ cordova.define('cordova/plugin_list', function(require, exports, module) { "cordova-plugin-brightness": "0.1.5", "cordova-plugin-fingerprint-aio": "3.0.1", "cordova-plugin-prevent-screenshot-coffice": "1.0.1", - "cordova-plugin-qqsdk": "0.9.7" + "cordova-plugin-qqsdk": "0.9.7", + "cordova-plugin-wechat": "3.0.0" }; }); \ No newline at end of file diff --git a/platforms/android/app/src/main/assets/www/main.html b/platforms/android/app/src/main/assets/www/main.html index 8cced49..d9dcb90 100644 --- a/platforms/android/app/src/main/assets/www/main.html +++ b/platforms/android/app/src/main/assets/www/main.html @@ -1,206 +1,242 @@ - - - - - - - - - - - - -
-
-
-
-
- -
-
- -
-
- -
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
读码
-
-
-
-
-
-
扫码
-
-
-
-
-
-
-
-
访码
-
-
-
-
-
-
更多
-
-
-
-
-
-
-
- - -
-
- -
首页
-
-
- -
消息
-
-
- -
我的
-
-
- - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + +
+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+
+
+
+
+
+
+
+
+
读码
+
+
+
+
+
+
扫码
+
+
+
+
+
+
+
+
访码
+
+
+
+
+
+
更多
+
+
+
+
+
+
+
+ + +
+
+ +
首页
+
+
+ +
消息
+
+
+ +
我的
+
+
+ + + + + + + + + + diff --git a/platforms/android/app/src/main/java/com/dalipolice/app/wxapi/EntryActivity.java b/platforms/android/app/src/main/java/com/dalipolice/app/wxapi/EntryActivity.java new file mode 100644 index 0000000..9d25f66 --- /dev/null +++ b/platforms/android/app/src/main/java/com/dalipolice/app/wxapi/EntryActivity.java @@ -0,0 +1,176 @@ +package com.dalipolice.app.wxapi; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; + +import com.tencent.mm.opensdk.constants.ConstantsAPI; +import com.tencent.mm.opensdk.modelbase.BaseReq; +import com.tencent.mm.opensdk.modelbase.BaseResp; +import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram; +import com.tencent.mm.opensdk.modelmsg.SendAuth; +import com.tencent.mm.opensdk.openapi.IWXAPI; +import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler; +import com.tencent.mm.opensdk.modelbiz.ChooseCardFromWXCardPackage; + +import org.apache.cordova.CallbackContext; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + + +import xu.li.cordova.wechat.Wechat; + +/** + * Created by xu.li on 9/1/15. + */ +public class EntryActivity extends Activity implements IWXAPIEventHandler { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + IWXAPI api = Wechat.getWxAPI(this); + + if (api == null) { + startMainActivity(); + } else { + api.handleIntent(getIntent(), this); + } + } + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + + setIntent(intent); + + IWXAPI api = Wechat.getWxAPI(this); + if (api == null) { + startMainActivity(); + } else { + api.handleIntent(intent, this); + } + + } + + @Override + public void onResp(BaseResp resp) { + Log.d(Wechat.TAG, resp.toString()); + + CallbackContext ctx = Wechat.getCurrentCallbackContext(); + + if (ctx == null) { + startMainActivity(); + return ; + } + + switch (resp.errCode) { + case BaseResp.ErrCode.ERR_OK: + switch (resp.getType()) { + case ConstantsAPI.COMMAND_SENDAUTH: + auth(resp); + break; + case ConstantsAPI.COMMAND_CHOOSE_CARD_FROM_EX_CARD_PACKAGE: + plunckInvoiceData(resp); + break; + case ConstantsAPI.COMMAND_LAUNCH_WX_MINIPROGRAM: + Log.d(Wechat.TAG, "miniprogram back;"); + WXLaunchMiniProgram.Resp miniProResp = (WXLaunchMiniProgram.Resp) resp; + launchMiniProResp(miniProResp); + break; + case ConstantsAPI.COMMAND_PAY_BY_WX: + default: + ctx.success(); + break; + } + break; + case BaseResp.ErrCode.ERR_USER_CANCEL: + ctx.error(Wechat.ERROR_WECHAT_RESPONSE_USER_CANCEL); + break; + case BaseResp.ErrCode.ERR_AUTH_DENIED: + ctx.error(Wechat.ERROR_WECHAT_RESPONSE_AUTH_DENIED); + break; + case BaseResp.ErrCode.ERR_SENT_FAILED: + ctx.error(Wechat.ERROR_WECHAT_RESPONSE_SENT_FAILED); + break; + case BaseResp.ErrCode.ERR_UNSUPPORT: + ctx.error(Wechat.ERROR_WECHAT_RESPONSE_UNSUPPORT); + break; + case BaseResp.ErrCode.ERR_COMM: + ctx.error(Wechat.ERROR_WECHAT_RESPONSE_COMMON); + break; + default: + ctx.error(Wechat.ERROR_WECHAT_RESPONSE_UNKNOWN); + break; + } + + finish(); + } + + @Override + public void onReq(BaseReq req) { + finish(); + } + + protected void startMainActivity() { + Intent intent = new Intent(); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.setPackage(getApplicationContext().getPackageName()); + getApplicationContext().startActivity(intent); + } + + protected void launchMiniProResp(WXLaunchMiniProgram.Resp launchMiniProResp){ + CallbackContext ctx = Wechat.getCurrentCallbackContext(); + String extraData =launchMiniProResp.extMsg; //对应小程序组件