xu-li / cordova-plugin-wechat

A cordova plugin, a JS version of Wechat SDK
1.22k stars 509 forks source link

Wechat auth method #551

Open duongduckien opened 5 years ago

duongduckien commented 5 years ago

I have used this plugin to authentication with native Wechat application. Application has redirected to native Wechat app, but I can't get any response from this function: Wechat.auth(scope, (response) => { console.log(response) }, (reason) => {}); What's the reason for this issue? Thanks!

jasonz1987 commented 5 years ago

hi,

i think you've missed the second param state properly.


Wechat.auth(scope, state, function (response) {
    // you may use response.code to get the access token.
    alert(JSON.stringify(response));
}, function (reason) {
    alert("Failed: " + reason);
});

``
duongduckien commented 5 years ago
Screen Shot 2019-08-25 at 1 59 48 A@jasonz1987

@jasonz1987 I have tried to add state param, but I got the same result. I can't get the response when native Wechat app pop to Ionic app. Do you have any idea? Thanks!

duongduckien commented 5 years ago

@jasonz1987 Can you help me?

jasonz1987 commented 4 years ago

@duongduckien which platform did you use? you should see debug log in android/studio console to check if there is any error.

duongduckien commented 4 years ago

@jasonz1987 I'm testing on IOS platform. I have debugged on a real device with Safari. I don't see any errors.

duongduckien commented 4 years ago

@jasonz1987 Do you have any example with Ionic for this plugin?

jasonz1987 commented 4 years ago

@duongduckien you should check url scheme and debug openURL method in your xcode project ,some plugins like ionic-plugin-deeplink or ionic-plugin-facebook will prevent openURL method.

https://www.jason-z.com/post/85

duongduckien commented 4 years ago

@jasonz1987 Oh, I have used ionic-plugin-deeplink andionic-plugin-facebook in my project. I will check your solution. Thanks!

duongduckien commented 4 years ago

Screen Shot 2019-08-26 at 5 14 03 PM @jasonz1987 How can I fix it?

royanon commented 4 years ago

As of today 2020-01-22, ionic-plugin-deeplinks has release a version of 1.0.21 which is not available in mpn, but only github. Seems to have fix it as they close jasonz's PR and release this version. However, it still doesn't work. Due to the line

      // [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
      [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLWithAppSourceAndAnnotationNotification object:openURLData]];

It work if unremark the first line and remark the second line. annotation is not available, so, openURLData is always empty.