Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 3 #615

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/android/EntryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +24,8 @@

import xu.li.cordova.wechat.Wechat;



/**
* Created by xu.li<[email protected]> on 9/1/15.
*/
Expand All @@ -30,6 +34,7 @@ public class EntryActivity extends Activity implements IWXAPIEventHandler {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Wechat.data = "";

IWXAPI api = Wechat.getWxAPI(this);

Expand Down Expand Up @@ -111,6 +116,17 @@ 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;
// Intent intent = getApplicationContext().getPackageManager().getLaunchIntentForPackage(getApplicationContext().getPackageName());
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// getApplicationContext().startActivity(intent);
Wechat.callJS(extInfo);
}
finish();
}

Expand Down Expand Up @@ -173,4 +189,4 @@ protected void plunckInvoiceData(BaseResp resp) {

ctx.success(response);
}
}
}
10 changes: 10 additions & 0 deletions src/android/Wechat.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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(callbackContext);
}

return false;
Expand Down Expand Up @@ -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;
}

}
2 changes: 2 additions & 0 deletions src/ios/CDVWechat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
18 changes: 18 additions & 0 deletions src/ios/CDVWechat.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -275,6 +285,14 @@ - (void)jumpToWechat:(CDVInvokedUrlCommand *)command
- (void)onReq:(BaseReq *)req
{
NSLog(@"%@", req);
//获取开放标签传递的 extinfo 数据逻辑
if ([req isKindOfClass:[LaunchFromWXReq class]])
{
LaunchFromWXReq* wxReq = (LaunchFromWXReq*)req;
WXMediaMessage *msg = wxReq.message;
NSString *extinfo = msg.messageExt;
self.wechatData = extinfo;
}
}

- (void)onResp:(WXLaunchMiniProgramResp *)resp
Expand Down
4 changes: 4 additions & 0 deletions www/wechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ module.exports = {
exec(onSuccess, onError, "Wechat", "isWXAppInstalled", []);
},

openApp: function (onSuccess, onError) {
exec(onSuccess, onError, "Wechat", "openApp", []);
},

/**
* Share a message to wechat app
*
Expand Down