jasonboy / wechat-jssdk Goto Github PK
View Code? Open in Web Editor NEW🐧微信JSSDK与NodeJS及Web端集成 WeChat JSSDK integration with NodeJS & Web
License: MIT License
🐧微信JSSDK与NodeJS及Web端集成 WeChat JSSDK integration with NodeJS & Web
License: MIT License
每次都会更新全局的access_token吗
在前端使用的话,appId和appSecret 会泄露吗?
"appId": "mp_appid",
"appSecret": "mp_app_secret",
hi! I'm trying to check how to use the oAuth part
what we really want is to get the user's openID when they are accessing an H5 page linked from within an official account (from a menu item actually)
looking at the oAuth callback
https://github.com/JasonBoy/wechat-jssdk#oauth
//default callback url
router.get('/wechat/oauth-callback', function (req, res) {
wx.oauth.getUserInfo(req.query.code)
.then(function(userProfile) {
console.log(userProfile)
res.render("demo", {
wechatInfo: userProfile
});
});
});
so this is server side code obviously. what is wx
in this case?
const wx = new WeChat(wechatInfo);
Am i right to understand,
you've created an npm wechat JS-SDK, which is different from the official tencent js-sdk
and you're suggesting to initialize it with wx
?
this is a bit confusing, as the client side official tencent SDK is also referred to as wx
in their examples.
你好,@JasonBoy,希望可以自定义scope,这样的话, 非公众号appid也可以使用这个package了
我看了package中的lib/oauth.js文件,里面有一些默认的配置,默认配置的scope是snsapi_userinfo,这个scope公众号(mp.weixin.qq.com)里面生成的appid可以使用,但是通过open.weixin.qq.com生成的开发者appid是无法使用的,open.weixin.qq.com里面生成的app只能使用snsapi_login scope,
但是在wechat-jssdk的package中并没有自定义scope的地方,希望可以配置一下,谢谢,这个sdk非常棒!
(也可能是我没有找到。如果是我没有找到,希望可以帮助下我,thx)
hi,配置中有paymentCertificatePfx: fs.readFileSync(path.join(process.cwd(), 'cert/apiclient_cert.p12')),而在vue-cli中无法引入fs,请问有什么解决方案?
var wx = require('wechat-jssdk');
提示Cannot find module "net"是什么原因
in early stage...
unifiedOrder之类的函数必须在服务器上调用,调试时非常麻烦,能够增加proxy设置可以轻松很多
since node has native ESM support
现在getCardExt 只有outer_str参数,我需要outer_id,能加上吗
H5页面用微信登录必须要扫二维码吗?
since it does not guarantee the signature is signed successfully!
现在有极小概率出现这个提示,可能是其他地方调用了access_token,导致我们自己的过期了,我目前就用了co-wechat-api和wechat-jssdk。
过期后我可能要等两个小时候业务才会恢复。能麻烦加入一个重新获取的机制吗,比如收到40001错误,就重新获取access_token,然后重新请求。
@JasonBoy 您好!现在使用nginx反向代码,如果直接使用www.gumpyang.com.cn就可以显示signature OK,但如果设置二级代码如www.gumpyang.com.cn/wxjs,打开时就会如下错误
GET http://www.gumpyang.com.cn/get-signature?url=http%3A%2F%2Fwww.gumpyang.com.cn%2Fwxjs%2F 404 (Not Found)
请教如何可以定位是我哪里设置错误了
有计划发布 deno 版本吗?
I sometimes got the error when get access token. Could you advise how to auto get a new code in this situation?
Hi,
I found this repo from Medium post. Great job!
However, after I checkout master repo I got follow Error, could you please help?
PS C:\Users\xxxx\Documents\GitHub\wechat_programs\WeChat-JSSDK-Backend> npm start
[email protected] start C:\Users\xxxx\Documents\GitHub\wechat_programs\WeChat-JSSDK-Backend
node ./bin/www
C:\Users\xxxx\Documents\GitHub\wechat_programs\WeChat-JSSDK-Backend\app.js:30
const wx = new Wechat(wechatConfig);
^TypeError: Wechat is not a constructor
at Object. (C:\Users\xxxx\Documents\GitHub\wechat_programs\WeChat-JSSDK-Backend\app.js:30:12)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object. (C:\Users\xxxx\Documents\GitHub\wechat_programs\WeChat-JSSDK-Backend\bin\www:7:11)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start:node ./bin/www
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\xxxx\AppData\Roaming\npm-cache_logs\2020-07-19T08_03_03_260Z-debug.log
PS C:\Users\xxxx\Documents\GitHub\wechat_programs\WeChat-JSSDK-Backend> npm -v
6.14.5
PS C:\Users\xxxx\Documents\GitHub\wechat_programs\WeChat-JSSDK-Backend> node -v
v12.18.2
PS C:\Users\xxxx\Documents\GitHub\wechat_programs\WeChat-JSSDK-Backend> npm run
Lifecycle scripts included in wechat-demo:
start
node ./bin/wwwavailable via
npm run-script
:
dev
nodemon ./bin/www
Is this coming from the version of nodejs and npm? I am using the latest version as below:
npm: 6.14.5
node: v12.18.2
Thanks
nodejs.TypeError: Wechat is not a constructor
Hi,
I can't seem to call the weChat.callWechatApi('updateAppMessageShareData', config) method. For some reason it says that 'There is no such SDK or this SDK simulation is not currently supported' in the response. I'm going by the documentation provided here, here's a screenshot of my code.
Can someone point me to the solution? Thanks.
should lock json file when one process is writing.
因为官方文档中写明了以前的分享api都将会弃用,请尽快迁移到最新1.4.0版本
报错
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 12): AssertionError [ERR_ASSERTION]: non-error thrown: [object Object]
我该如何发起NATIVE订单 返回包含code_url
Payment.js generateChooseWXPayInfo函数 appId: this.wechatConfig.appId
这个会appid是我的公众号appid,在miniProgram下还有一个appid这个是小程序的
那么,我在生成wx.requestPayment所需内容的时候签名就有问题了。
请问,现在支付是不是还没有完全适配小程序?
系统:Ubuntu 18.04.3 x64
Node:v12.14.1
MongoDB: 4.0.3 (升级至4.2.2一样
只用了小程序的功能
const { Wechat, MongoStore } = require('wechat-jssdk')
// =========> TypeError: Cannot read property 'findOneAndUpdate' of undefined <==========
const mongoStore = new MongoStore({
dbHost: process.env.DB_HOST,
dbPort: process.env.DB_PORT,
dbName: 'cat',
dbOptions: {
user: process.env.DB_USER,
pass: process.env.DB_PASS,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
}, // extra options passed to mongoose
limit: 10 // how many url signature and oauth token items should be initialized from db, default: 20
})
const wechatConfig = {
appId: process.env.APP_ID,
appSecret: process.env.APP_SECRET,
// 小程序配置
miniProgram: {
appId: process.env.APP_ID,
appSecret: process.env.APP_SECRET
},
store: mongoStore
}
const wx = new Wechat(wechatConfig)
module.exports = wx
/home/nodejs-web/mpi-miniprogram/node_modules/wechat-jssdk/lib/store/MongoStore.js:350
return this.GlobalToken.findOneAndUpdate({}, Object.assign({}, gt), {
^
TypeError: Cannot read property 'findOneAndUpdate' of undefined
at MongoStore.flushGlobalToken (/home/nodejs-web/mpi-miniprogram/node_modules/wechat-jssdk/lib/store/MongoStore.js:350:31)
at MongoStore.flush (/home/nodejs-web/mpi-miniprogram/node_modules/wechat-jssdk/lib/store/MongoStore.js:473:12)
at Timeout._onTimeout (/home/nodejs-web/mpi-miniprogram/node_modules/wechat-jssdk/lib/store/Store.js:100:47)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)
版本:"wechat-jssdk": "^3.0.11"
const weConfig = {
......
jsApiList:['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQZone'],
success:function(wechatObj ){ console.log('签名成功');},
......
}
const wechatObj = new WechatJSSDK(weConfig);
开启debug
签名成功的回调能执行到
当调用 wechatObj.callWechatApi('onMenuShareTimeline', apiConfig);
这是什么情况
会考虑将 1.0.0版本升级为 1.2.0版本吗?
通过指定CustomURL为http://res2.wx.qq.com/open/js/jweixin-1.6.0.js,加载微信 jssdk 1.6.0。
后台计算 url 的签名好像也没啥问题。
前端调用代码好像也没什么问题。
用的下面两个接口:
updateAppMessageShareData
updateTimelineShareData
但是无法调起 IOS 微信客户端。
具体可以参考图片。
Hi.
Don't understand when and where I should to use verify from paragraph 1 here (https://github.com/JasonBoy/wechat-jssdk#setup-your-wechat-env).
Should it be configured somewhere in wechat account (because you wrote "let wechat to verify" or I should call it myself somewhere?
Thanks.
const wechatObj = new WechatJSSDK(config);
wechatObj.initialize()
.then(w => {
console.log('wechatObj w: ', w);// deos not run
//set up your share info, "w" is the same instance as "wechatObj"
})
.catch(err => {
console.error(err);
});
I only get this log 'Wechat script loaded successfully!'.
paymentCertificatePfx 可以默认缺省嘛
Refactor project with TypeScript
typescript 的版本 ,目前有办法用么
@JasonBoy 请教一下,现在部署OK后,点击OAuth和OAuth without new code都会显示
wechat Error: please get new code!
wechat at /home/gump/work/gump/github/wechat-jssdk/lib/OAuth.js:164:23
wechat at process._tickCallback (node.js:368:9) +0ms
查看key都是undefined,打印req.session后,信息如下
{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"}}
其中没有openid,请教是配置的问题吗?
同时请教demo下的oauth.html是点击OAuth后跳转吗?
currently all tests are based on the wechat server apis, aka e2e tests, which really slow down the test process, also it's hard to test some error handling, so it could be great to also add stubs to boost UT testing.
const wxObj = new WechatJSSDK({
...wxConf,
'success': () => {
console.log(wxObj.wx, '????')
},
})
console.error(wxObj.wx)
setTimeout(() => console.error(wxObj.wx, '~!!!!!!!'), 1500)
sucess回调里面的没有被调用,
只有settimeout可以取到wxObj.wx
用import时,提示define 错误,去掉后提示如下:
import WechatJSSDK from '../components/weichat-jssdk/client'
"export 'default' (imported as 'WechatJSSDK') was not found in 'weichat-jssdk/client'
采用//const WechatJSSDK = require( '/weichat-jssdk/client')用的时候浏览器出错
刚new完WechatJSSDK,并不能马上获取到window.wx,那么自然而然使用里面的callWechatApi方法通通报错!!,看了源码才发现new的过程中还有一个loadScript方法在异步加载核心库,这下蛋疼了,没有对外提供一个ready方法让我们等待这个异步,那么何时使用wx的方法,很苦恼,计时器都不那么好用,希望能提供一个该接口(考虑做个事件触发器单独触发一个ready,或者构造器里面直接弄个回调也可以简单粗暴好用)。谢谢
Math.floor(Number(77.6) * 100) = 7759 !!!
please fix it.
如题,之前都是好好的,不知道为何从7月6号开始出现这种错误,而且不是100%出现,是小几率正常
{ ReadError: unknown compression method
at EventEmitter.emitter.on (/var/www/XXXX/deploy/node_modules/_got@9.6.0@got/source/as-promise.js:28:12)
at process._tickCallback (internal/process/next_tick.js:68:7)
name: 'ReadError',
code: 'Z_DATA_ERROR',
host: 'api.mch.weixin.qq.com',
hostname: 'api.mch.weixin.qq.com',
method: 'POST',
path: '/pay/unifiedorder',
....
不支持的压缩方法???没找到是哪里的原因,是微信支付请求处理改版了还是其他什么BUG?
我尝试把got换成了axios,就恢复正常了,希望关注下,目前在我们项目中got确实有问题
你好!
我按照readme配置了微信公众平台,并修改了index.js后,点击Oauth一直有问题。步骤是:
配置:
请问以上配置步骤是否有问题?有哪里做得不对吗?
非常感谢!
TODO
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.