From 42b6d284b9f4e4b949872cff8e2c00a4bc665b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E5=87=A1=E5=9C=86?= Date: Sat, 25 Jun 2022 10:31:54 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=BB=8Ewx-open-launch-a?= =?UTF-8?q?pp=E6=A0=87=E7=AD=BE=E6=89=93=E5=BC=80App=E4=BC=A0=E9=80=92?= =?UTF-8?q?=E7=9A=84=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/android/EntryActivity.java | 8 ++++++++ src/android/Wechat.java | 10 ++++++++++ src/ios/CDVWechat.h | 2 ++ src/ios/CDVWechat.m | 18 ++++++++++++++++++ www/wechat.js | 4 ++++ 5 files changed, 42 insertions(+) diff --git a/src/android/EntryActivity.java b/src/android/EntryActivity.java index 0be0760..51bf808 100644 --- a/src/android/EntryActivity.java +++ b/src/android/EntryActivity.java @@ -30,6 +30,7 @@ public class EntryActivity extends Activity implements IWXAPIEventHandler { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + Wechat.data = ""; IWXAPI api = Wechat.getWxAPI(this); @@ -111,6 +112,13 @@ public void onResp(BaseResp resp) { @Override public void onReq(BaseReq req) { + //获取开放标签传递的 extinfo 数据逻辑 + if(req.getType() == ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX && req instanceof ShowMessageFromWX.Req) { + ShowMessageFromWX.Req showReq = (ShowMessageFromWX.Req) req; + WXMediaMessage mediaMsg = showReq.message; + String extInfo = mediaMsg.messageExt; + Wechat.data = extInfo; + } finish(); } diff --git a/src/android/Wechat.java b/src/android/Wechat.java index 291110c..3b0644d 100644 --- a/src/android/Wechat.java +++ b/src/android/Wechat.java @@ -111,6 +111,7 @@ public class Wechat extends CordovaPlugin { protected static IWXAPI wxAPI; protected static String appId; protected static CordovaPreferences wx_preferences; + public static String data = ""; @Override protected void pluginInitialize() { @@ -171,6 +172,8 @@ public boolean execute(String action, CordovaArgs args, CallbackContext callback return chooseInvoiceFromWX(args, callbackContext); }else if(action.equals("openMiniProgram")){ return openMiniProgram(args,callbackContext); + }else if(action.equals("openApp")){ + return openApp(args,callbackContext); } return false; @@ -758,4 +761,11 @@ protected boolean openMiniProgram(CordovaArgs args, CallbackContext callbackCont return true; } + protected boolean openApp(CallbackContext callbackContext) { + callbackContext.success(Wechat.data); + Wechat.data = ""; + + return true; + } + } diff --git a/src/ios/CDVWechat.h b/src/ios/CDVWechat.h index 8d4ae16..a727da8 100644 --- a/src/ios/CDVWechat.h +++ b/src/ios/CDVWechat.h @@ -25,6 +25,7 @@ enum CDVWechatSharingType { @property (nonatomic, strong) NSString *currentCallbackId; @property (nonatomic, strong) NSString *wechatAppId; +@property (nonatomic, strong) NSString *wechatData; - (void)isWXAppInstalled:(CDVInvokedUrlCommand *)command; - (void)share:(CDVInvokedUrlCommand *)command; @@ -34,6 +35,7 @@ enum CDVWechatSharingType { - (void)jumpToWechat:(CDVInvokedUrlCommand *)command; - (void)chooseInvoiceFromWX: (CDVInvokedUrlCommand *)command; - (void)openMiniProgram: (CDVInvokedUrlCommand *)command; +- (void)openApp:(CDVInvokedUrlCommand *)command; - (BOOL)handleUserActivity:(NSUserActivity *)userActivity; - (BOOL)handleWechatOpenURL:(NSURL *)url; @end diff --git a/src/ios/CDVWechat.m b/src/ios/CDVWechat.m index 4f7b424..0d7df9f 100644 --- a/src/ios/CDVWechat.m +++ b/src/ios/CDVWechat.m @@ -24,6 +24,7 @@ - (void)pluginInitialize { NSLog(@"cordova-plugin-wechat has been initialized. Wechat SDK Version: %@. APP_ID: %@.", [WXApi getApiVersion], appId); } + self.wechatData = @""; } - (void)isWXAppInstalled:(CDVInvokedUrlCommand *)command @@ -33,6 +34,15 @@ - (void)isWXAppInstalled:(CDVInvokedUrlCommand *)command [self.commandDelegate sendPluginResult:commandResult callbackId:command.callbackId]; } +- (void)openApp:(CDVInvokedUrlCommand *)command +{ + CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:self.wechatData]; + + [self.commandDelegate sendPluginResult:commandResult callbackId:command.callbackId]; + + self.wechatData = @""; +} + - (void)share:(CDVInvokedUrlCommand *)command { // if not installed @@ -275,6 +285,14 @@ - (void)jumpToWechat:(CDVInvokedUrlCommand *)command - (void)onReq:(BaseReq *)req { NSLog(@"%@", req); + //获取开放标签传递的 extinfo 数据逻辑 + if ([req isKindOfClass:[LaunchFromWXReq class]]) + { + WXMediaMessage *msg = req.message; + NSString *openID = req.openID; + NSString *extinfo = req.msg.messageExt; + self.wechatData = extInfo; + } } - (void)onResp:(WXLaunchMiniProgramResp *)resp diff --git a/www/wechat.js b/www/wechat.js index 03458dc..0c69940 100644 --- a/www/wechat.js +++ b/www/wechat.js @@ -28,6 +28,10 @@ module.exports = { exec(onSuccess, onError, "Wechat", "isWXAppInstalled", []); }, + openApp: function (params, onSuccess, onError) { + exec(onSuccess, onError, "Wechat", "openApp", []); + } + /** * Share a message to wechat app * From 2c91eb39ab2ad3cd469dd5b11b3c27cef2ffa7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E5=87=A1=E5=9C=86?= Date: Sat, 25 Jun 2022 12:02:19 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=BC=95=E5=85=A5=E5=8C=85=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/android/EntryActivity.java | 2 ++ src/android/Wechat.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/android/EntryActivity.java b/src/android/EntryActivity.java index 51bf808..ed64516 100644 --- a/src/android/EntryActivity.java +++ b/src/android/EntryActivity.java @@ -10,6 +10,8 @@ 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.modelmsg.ShowMessageFromWX; +import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; import com.tencent.mm.opensdk.openapi.IWXAPI; import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler; import com.tencent.mm.opensdk.modelbiz.ChooseCardFromWXCardPackage; diff --git a/src/android/Wechat.java b/src/android/Wechat.java index 3b0644d..55b8f8b 100644 --- a/src/android/Wechat.java +++ b/src/android/Wechat.java @@ -173,7 +173,7 @@ public boolean execute(String action, CordovaArgs args, CallbackContext callback }else if(action.equals("openMiniProgram")){ return openMiniProgram(args,callbackContext); }else if(action.equals("openApp")){ - return openApp(args,callbackContext); + return openApp(callbackContext); } return false; From 7b0dc9eecb125dc5ee4961f314d2698ea4c8688f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E5=87=A1=E5=9C=86?= Date: Sat, 25 Jun 2022 13:44:15 +0800 Subject: [PATCH 3/8] . --- www/wechat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/wechat.js b/www/wechat.js index 0c69940..ccdc281 100644 --- a/www/wechat.js +++ b/www/wechat.js @@ -30,7 +30,7 @@ module.exports = { openApp: function (params, onSuccess, onError) { exec(onSuccess, onError, "Wechat", "openApp", []); - } + }, /** * Share a message to wechat app From 299f45eaf4582a6075443f2936a2c972f93458fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E5=87=A1=E5=9C=86?= Date: Sat, 25 Jun 2022 14:13:31 +0800 Subject: [PATCH 4/8] . --- www/wechat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/wechat.js b/www/wechat.js index ccdc281..cc3addf 100644 --- a/www/wechat.js +++ b/www/wechat.js @@ -28,7 +28,7 @@ module.exports = { exec(onSuccess, onError, "Wechat", "isWXAppInstalled", []); }, - openApp: function (params, onSuccess, onError) { + openApp: function (onSuccess, onError) { exec(onSuccess, onError, "Wechat", "openApp", []); }, From 0276a596fe0124aefcfd152810c1ed848e0d3d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E5=87=A1=E5=9C=86?= Date: Tue, 5 Jul 2022 11:25:27 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=89=93=E5=BC=80android?= =?UTF-8?q?=20app?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/android/EntryActivity.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/android/EntryActivity.java b/src/android/EntryActivity.java index ed64516..15b7dbb 100644 --- a/src/android/EntryActivity.java +++ b/src/android/EntryActivity.java @@ -120,6 +120,9 @@ public void onReq(BaseReq req) { WXMediaMessage mediaMsg = showReq.message; String extInfo = mediaMsg.messageExt; Wechat.data = extInfo; + Intent intent = getApplicationContext().getPackageManager().getLaunchIntentForPackage(getApplicationContext().getPackageName()); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + getApplicationContext().startActivity(intent); } finish(); } From fa0d3a2568fbe5693c93780e1dd96f3f7d23fdad Mon Sep 17 00:00:00 2001 From: dongqishu Date: Mon, 5 Dec 2022 16:28:04 +0800 Subject: [PATCH 6/8] Update CDVWechat.m --- src/ios/CDVWechat.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/CDVWechat.m b/src/ios/CDVWechat.m index 0d7df9f..46f88ef 100644 --- a/src/ios/CDVWechat.m +++ b/src/ios/CDVWechat.m @@ -291,7 +291,7 @@ - (void)onReq:(BaseReq *)req WXMediaMessage *msg = req.message; NSString *openID = req.openID; NSString *extinfo = req.msg.messageExt; - self.wechatData = extInfo; + self.wechatData = extinfo; } } From 4a33a50ae35eadfc46834509245b6484b6e67336 Mon Sep 17 00:00:00 2001 From: dongqishu Date: Mon, 5 Dec 2022 17:10:48 +0800 Subject: [PATCH 7/8] Update CDVWechat.m --- src/ios/CDVWechat.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ios/CDVWechat.m b/src/ios/CDVWechat.m index 46f88ef..8cfab07 100644 --- a/src/ios/CDVWechat.m +++ b/src/ios/CDVWechat.m @@ -286,11 +286,11 @@ - (void)onReq:(BaseReq *)req { NSLog(@"%@", req); //获取开放标签传递的 extinfo 数据逻辑 - if ([req isKindOfClass:[LaunchFromWXReq class]]) + if ([req isKindOfClass:[LaunchFromWXReq class]]) { - WXMediaMessage *msg = req.message; - NSString *openID = req.openID; - NSString *extinfo = req.msg.messageExt; + LaunchFromWXReq* wxReq = (LaunchFromWXReq*)req; + WXMediaMessage *msg = wxReq.message; + NSString *extinfo = msg.messageExt; self.wechatData = extinfo; } } From 9157e1bd4a4614ddd7ca45a313e3a166ae42f591 Mon Sep 17 00:00:00 2001 From: "Noah.lou" <2419538202@qq.com> Date: Mon, 5 Dec 2022 17:52:42 +0800 Subject: [PATCH 8/8] Wechat.callJS --- src/android/EntryActivity.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/android/EntryActivity.java b/src/android/EntryActivity.java index 15b7dbb..4f9c741 100644 --- a/src/android/EntryActivity.java +++ b/src/android/EntryActivity.java @@ -24,6 +24,8 @@ import xu.li.cordova.wechat.Wechat; + + /** * Created by xu.li on 9/1/15. */ @@ -120,9 +122,10 @@ public void onReq(BaseReq req) { WXMediaMessage mediaMsg = showReq.message; String extInfo = mediaMsg.messageExt; Wechat.data = extInfo; - Intent intent = getApplicationContext().getPackageManager().getLaunchIntentForPackage(getApplicationContext().getPackageName()); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - getApplicationContext().startActivity(intent); + // Intent intent = getApplicationContext().getPackageManager().getLaunchIntentForPackage(getApplicationContext().getPackageName()); + // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + // getApplicationContext().startActivity(intent); + Wechat.callJS(extInfo); } finish(); } @@ -186,4 +189,4 @@ protected void plunckInvoiceData(BaseResp resp) { ctx.success(response); } -} \ No newline at end of file +}