Wechat : OAuth with test account
Asked Answered
G

1

5

I'm actually trying to set up a OAuth login with WeChat for my web application. So, I have create a account on wechat, and I used a Test account to have all access unlimited.

So, on the test account configuration, I have successfully validate the token from wechat (see here : http://admin.wechat.com/wiki/index.php?title=Getting_Started).

On the doc, OAuth is explain here : http://admin.wechat.com/wiki/index.php?title=User_Profile_via_Web

We must redirect user to this URL for login: https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect

I have replace APPID by my test account AppId, my redirect URI like : http://wechat.mydomain.net, SCOPE by the correct one (snsapi_userinfo) and remove the state param (optional). But, I had a error on Wechat :

Oops! Something went wrong:(

After hours of research, I set the domain on "Api permission list", in " Webpage Account" Wechat configuration

But I always have this error. Maybe I missing something, but I don't find what. There is my final URL called : https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8ytvf5838cc7t33d&redirect_uri=http://wechat.mydomain.net/wechat/callback&response_type=code&scope=snsapi_userinfo&connect_redirect=1#wechat_redirect

Thanks for your help !

Gondi answered 19/4, 2016 at 8:12 Comment(2)
Hi I got same problem did you solve the problem.Spectroscopy
I have the same issue using mp.weixin.qq.com/debug/cgi-bin/sandboxinfo (which doesn't require an official account). I have one user following the test account (me), and successfully validated the token. Calling the OAuth URL withing wechat with my follower account gives me the same result as you (Oops! Something went wrong:()Lash
T
8

Hope it still relevant for you (or anyone else)

The WeChat oAuth seems to be only available from an Official account and not supported in the Test account.

If you have an approved official account, you can check it under the permissions tab in the admin.

Anyway - the login callback will always return an error if not called from the WeChat native application. You can not just open it in the browser.

You can check my PHP class at GitHub, it includes (for now) the oAuth and the messages engine: https://github.com/nitzanb/wechat-class

Touchmenot answered 15/5, 2016 at 5:37 Comment(5)
I've just had the same issue. I thought you'd be able to log someone in via a website and store their auth token. So you're saying this can only be done via an app maybe?Guardroom
The auth token only work through the WeChat native application. If you want to login a user in a website using his WeChat ID, I recommend that you'll check the QR code interface.Touchmenot
Thanks for the reply! Could you give a web address please for me to take a look at the process? I've tried looking into this but can't find information anywhere. Cheers!Guardroom
This URL might help. It's in Chinese though. mp.weixin.qq.com/wiki?t=resource/…Touchmenot
WeChat oAuth does work with sandbox test accounts. Though it needs to be called from inside the wechat app.Casia

© 2022 - 2024 — McMap. All rights reserved.