zhaoyao91 / meteor-accounts-wechat-mp Goto Github PK
View Code? Open in Web Editor NEWmeteor accounts package for wechat-mp
meteor accounts package for wechat-mp
Have you been able to integrate the plugin with Cordova ?
You give reference to boxfish:meteor-wechat (which seems totally broken), so I thought maybe you tried it before.
在getTokenResponse()和getIdentity()中都有HTTP.get查询微信接口,返回值是这样处理的:
if (response.error) // if the http response was an error
throw response.error;
if (typeof response.content === "string")
response.content = JSON.parse(response.content);
if (response.content.error)
throw response.content;
Meteor的文档是这样说的:
When run in synchronous mode, either result is returned from the function, or error is thrown.
Contents of the result object:
statusCode Number
Numeric HTTP result status code, or null on error.
content String
The body of the HTTP response as a string.
data Object or null
If the response headers indicate JSON content, this contains the body of the document parsed as a JSON object.
headers Object
A dictionary of HTTP headers from the response.
所以:
比如我用一个过期的access token查询https://api.weixin.qq.com/sns/userinfo接口,结果如下:
curl -v https://api.weixin.qq.com/sns/userinfo\?access_token\=w1INhgRMe11Y_MEXe5_BBgYrxFNzBy9nXgfhaEqtz5n1AVjj7CAB0zwIp08dahb5zTA40yJFE7yFptzFt11WvPcdL-rjP9chlwWfEnRdihQ\&openid\=owKOmuAhaxPcr8Vq0eWJ6H2tCgu0\&lang\=zh-CN
* Trying 103.7.30.34...
* TCP_NODELAY set
* Connected to api.weixin.qq.com (103.7.30.34) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: mp.weixin.qq.com
* Server certificate: GeoTrust SSL CA - G3
* Server certificate: GeoTrust Global CA
> GET /sns/userinfo?access_token=w1INhgRMe11Y_MEXe5_BBgYrxFNzBy9nXgfhaEqtz5n1AVjj7CAB0zwIp08dahb5zTA40yJFE7yFptzFt11WvPcdL-rjP9chlwWfEnRdihQ&openid=owKOmuAhaxPcr8Vq0eWJ6H2tCgu0&lang=zh-CN HTTP/1.1
> Host: api.weixin.qq.com
> User-Agent: curl/7.51.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Connection: keep-alive
< Content-Type: text/plain
< Date: Fri, 28 Apr 2017 01:11:07 GMT
< Content-Length: 84
<
* Curl_http_done: called premature == 0
* Connection #0 to host api.weixin.qq.com left intact
{"errcode":42001,"errmsg":"access_token expired, hints: [ req_id: O.VrUa0867ns88 ]"}%
在getIdentity()的代码中,response.content
就是{"errcode":42001,"errmsg":"access_token expired, hints: [ req_id: O.VrUa0867ns88 ]"}
,经过JSON.parse后正常返回。从这样parse得到的对象里再去取nickname
、headimgurl
等属性,结果都是undefined。
这段对HTTP.get返回值的处理代码,在一切正常时确实能返回正确的结果,出错时却并不能抛出异常。
我们在实际部署中遇到过几次这样的情况,用户登录后创建的账户中profile里只有openId等属性,而没有用户个人信息的nickname等属性。
I have been playing around with the lib and found a couple of problems.
First of all, the package zhaoyao91:short-oauth-state should be made mandatory, I knocked my head on the wall to find out why weixin was refusing my requests.
Another problem is that my callback in Meteor.loginWithWechatMP(function callback(err) {
// never executed...
});
I does work for well for the open platform with loginWithWechat().
At the moment I directly hacked the Oauth package overwritting OAuth.getDataAfterRedirect to detect the return from weixin. It works but it's definitely not a good practice...
Is the callback working for you ?
看到代码里登陆回调每次都会调用,这样不会导致老的token失效吗?正确的做法不是获取后保存复用,过7200秒再刷新么?而且微信限制了一天最多只能调用2000次,用户登录数量大的话很容易就被拒绝服务了吧
当用户微信信息更改时候,使用微信登录,用户profile还是以前的信息。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.