tencentyun / wafer2-node-sdk Goto Github PK
View Code? Open in Web Editor NEWWafer2 SDK for Node.js
License: Other
Wafer2 SDK for Node.js
License: Other
SDK 暴露了 Mysql 的链接; 意思就是天然支持mysql, 不支持mongodb?
文档不够详细
client端没有使用wafer2-client-sdk,自己组织的请求,发送到服务器端。有时会在解密数据时发生错误。
错误如下。烦请帮忙排查,谢谢。
错误信息:
ERR_IN_DECRYPT_DATA
Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
报错代码行:
wafer2-node-sdk/lib/auth/index.js
Line 43 in d2e486e
wafer-node-sdk 已升级到 1.4.5,问题依然存在
【nodemon提示报错如下】
koa-weapp-demo Catch Error: TypeError: Cannot read property 'user_info' of undefined at AuthDbService.getUserInfoByOpenId.then.userinfo (/data/release/weapp/node_modules/wafer-node-sdk/lib/auth/index.js:41:56) at runCallback (timers.js:810:20) at tryOnImmediate (timers.js:768:5) at processImmediate [as _immediateCallback] (timers.js:745:5) From previous event: at Builder.Target.then (/data/release/weapp/node_modules/knex/lib/interface.js:36:24) at getSessionKey.then.pkg (/data/release/weapp/node_modules/wafer-node-sdk/lib/auth/index.js:40:62) at at process._tickCallback (internal/process/next_tick.js:188:7) +2ms
【/……/auth/index.js附近代码】
// 如果只有 code 视为仅使用 code 登录
if (code && !encryptedData && !iv) {
return getSessionKey(code).then(pkg => {
const { openid, session_key } = pkg
// 生成 3rd_session
const skey = sha1(session_key)
return AuthDbService.getUserInfoByOpenId(openid).then(userinfo => {
const wxUserInfo = JSON.parse(userinfo.user_info)
return AuthDbService.saveUserInfo(wxUserInfo, skey, session_key)
.then(userinfo => ({
loginState: LOGIN_STATE.SUCCESS,
userinfo: {
userinfo: wxUserInfo,
skey: userinfo.skey
}
}))
})
})
}
【getUserInfoByOpenId方法对应的部分代码】
/**
* 通过 openid 获取用户信息
* @param {string} openid 用户的 openid
*/
function getUserInfoByOpenId (openId) {
if (!openId) throw new Error(ERRORS.DBERR.ERR_NO_OPENID_ON_CALL_GETUSERINFOFUNCTION)
return mysql('cSessionInfo').select('*').where({ open_id: openId }).first()
}
【疑问&求助】
同样server代码,在腾讯云免费开发环境就正常,本地调试的时候就报错,看起来是从cSessionInfo中没有查询到数据,,,
感觉很奇怪:在该步骤前,似乎没调用过AuthDbService.saveUserInfo……如果确实是这样,那cSessionInfo里根本没有数据啊,AuthDbService.getUserInfoByOpenId必然报错啊,,,
还是我哪里看错了,求大神帮忙解答TAT
when can we support mongodb wx auth?
不是单步调试,是输出debug信息。比如输出koa-weapp-demo的调试信息:
const debug = require('debug')('koa-weapp-demo')
开发中发现,用sdk中的mysql时返回的数据中时间和**时间差了8小时,我估计是knex的时区配置问题,所以问下,为啥关于mysql的配置项中没有时区的配置
测试环境上传服务器后,图片链接为
https://lovestory-1256082311.cos.ap-shanghai.myqcloud.com/1518221435533-rJVKO2iLM.png,而实际返回的链接为
https://lovestory-1256082311.cossh.myqcloud.com/1518221435533-rJVKO2iLM.png,
我看历史记录貌似是特意改的,是不是因为测试环境跟实际环境不同造成的,还是cos服务器的返回有变更出入
*** 如果购买了腾讯云小程序解决方案,配置项中 serverHost, tunnelServerUrl, tunnelSignatureKey, qcloudAppId, qcloudSecretId, qcloudSecretKey, wxMessageToken 由腾讯云自动下发到您的开发环境和生产环境上。
我在本地启动 node服务来调试信道
tunnelServerUrl
tunnelSignatureKey
不知道在哪找,在腾讯云管理平台找了好久没看到。
qcloudAppId
qcloudSecretId
qcloudSecretKey
这三个参数倒是找到了。
已经添加并测试。请合并到主分支。
Pull request:#2
我看的流程是下面这个链接里的,很详细,很棒,但是我的还是出了问题
https://github.com/tencentyun/wafer2-startup/wiki/%E8%87%AA%E8%A1%8C%E9%83%A8%E7%BD%B2
我腾讯云服务器的nginx要比教程里的高,教程是1.10 我的是1.14
教程里面给的yum的nodejs源在我服务器上直接被surpport到了版本v10
但是教程里面的node -v是v8.4.0
于是在服务器拷贝好的serve目录下,npm install时,r错误第一次出现,就是下面这个
npm ERR! notarget No matching version found for wafer-node-sdk@^1.4.1
我还以是不是对node版本有要求,于是又卸载并且yum clean all,重新安装了nodejs官网的二进制v8.4.0做了软链接到bin里。
这次node -v和教程里面一样了,都是v8.4.0 npm教程里没看到,我的是5.3.0
但是npm ERR! notarget No matching version found for wafer-node-sdk@^1.4.1 这个错误依然出现
我看在咱们这个node-sdk里,版本也确实已经迭代到了1.4.1
不知道问题出现在哪里,还望大佬能给方法让我继续摸索 :)
感激不尽!
Jest testEnvironment node throw error
FAIL test/services/tmpl/user.test.js
● Test suite failed to run
ERR_INIT_SDK_LOST_CONFIG
34 | // 初始化 SDK
35 | // 将基础配置和 sdk.config 合并传入 SDK 并导出初始化完成的 SDK
> 36 | module.exports = qcloud(Object.assign({}, sdkConfig, configs));
| ^
37 |
at init (node_modules/wafer-node-sdk/index.js:48:190)
at Object.<anonymous> (src/qcloud.js:36:18)
at Object.<anonymous> (src/services/tmpl/user.js:2:1)
at Object.<anonymous> (test/services/tmpl/user.test.js:1:1)
async uploadImage(ctx){
let result = await wafer.uploader(ctx.req)
ctx.state.data = result.uploadFolder+result.name
}
0|index | warning: AppId has been deprecated, Please put it at the end of parameter Bucket(E.g: "test-1250000000").
0|index | (node:7948) [DEP0013] DeprecationWarning: Calling an asynchronous function without callback is deprecated.
文件可以正常上传,但会报两个错误
在wafer2-node-sdk/lib/upload/ 目录下的index文件里面的fileType判断有问题,会把mp3格式的文件判断为webm格式
const imgKey = ${Date.now()}-${shortid.generate()}
+ resultType.ext ? .${resultType.ext}
: ''
wafer2-node-sdk/lib/upload/index.js
Line 126 in 6a69a25
如果指定了 uploadFolder , 这个地址是不是应该在域名后面加个 uploadFolder 的文件夹前缀?
另外,可否将各种参数单独返回回来可供用户自定义拼接url?举个例子,比如说有种场景是我希望用https的链接地址,返回的http协议的地址不能满足我的需求。
wafer-sdk的upload非常的好用,但是没有COS的DELETE接口,虽然想自己写但是水平有限,希望官方能提供一个,万望达成!
batchInsert 似乎用不了,报没有该方法错误
直接关闭微信,在服务端监不到tunnel的关闭,无法清理内存数据,tunnelId一直存在
微信并不推荐开发者在一进入就获取用户的信息比如头像昵称等等,事实上我们也没有必要获取这些。但是我们需要获取用户的openID,登录接口却默认获取了用户的信息,可否把获取用户信息做成一个可选项?只获取openID
点进去404了。要么删了link,要么改一下?
如果没有购买小程序解决方案, 我改如何获取这两个东西呢?我单独购买的腾讯云服务器。(其实当时就是想试试小程序,当时还没有什么方案)
虽然没直接写出, 但是可以看出来使用这个SDK的前提是使用koa框架儿不是express?
/lib/mysql/index 中 knex connection 初始化信息如下
module.exports = require('knex')({
client: 'mysql',
connection: {
host: configs.mysql.host,
port: configs.mysql.port,
user: configs.mysql.user,
password: configs.mysql.pass,
database: configs.mysql.db,
charset: configs.mysql.char
}
})
其中缺少 timezone 配置,应该添加配置 timezone: 'UTC'。否则使用使用这个配置返回的timestamp 内容会被自动回退8个小时,导致时间错误。请验证。
我看自动部署文档中说sdk只支持5.7的MySQL,如何支持5.6版本呢?
某种场景,我希望在一个工程里面使用两个不同的信道URL做不同业务,发现有BUG。
假设:
然后在分别在对应的GET方法中使用tunnel.getTunnelUrl(ctx.req)
返回信道的连接URL,但客户端连接后通信会出现消息错乱,比如发给学生的消息出现在老师的处理逻辑中,原因是lib/tunnel/service.js中的receiveUrl方法中做了一个Cache,导致两个业务GET方法中的getTunnelUrl传给信道服务器的receiverUrl是同一个。
如果真有这种场景,可以修改lib/tunnel/service.js,删除缓存的逻辑:
function receiveUrl (pathname) {
const protocol = url.parse(config.tunnelServerUrl).protocol
const hostname = config.serverHost
const port = config.serverPort // 配置端口号,undefined则无效果
return url.format({ protocol, hostname, port, pathname })
}
本地的环境可以使用sqlite,无需安装mysql,前端更快上手
简单的看了一下源代码, 信道接口是不是存在安全漏洞?
// 创建信道,需要给定后台服务地址
var tunnel = this.tunnel = new qcloud.Tunnel('https://199447.qcloud.la/tunnel');
如果知道 rul,就可以向这个地址发送模拟数据?
因为发现腾讯云的 mysql 数据库,并没有执行 npm run initdb 这个命令
在 phpMyAdmin 中没有看见有表结构生成。
请问一下,如何执行数据库脚本
wafer-node-sdk\lib\auth\index.js
原代码:
// 如果只有 code 视为仅使用 code 登录
if (code && !encryptedData && !iv) {
return getSessionKey(code).then(pkg => {
const { openid, session_key } = pkg
// 生成 3rd_session
const skey = sha1(session_key)
return AuthDbService.getUserInfoByOpenId(openid).then(userinfo => {
**wxUserInfo = JSON.parse(userinfo.user_info)**
return AuthDbService.saveUserInfo(wxUserInfo, skey, session_key)
.then(userinfo => ({
loginState: LOGIN_STATE.SUCCESS,
userinfo: {
userinfo: wxUserInfo,
skey: userinfo.skey
}
}))
})
})
}
这一句在新用户初次登录时,从cSessionInfo表查回的信息必然为空,导致JSON.parse抛出异常
此处建议修改为:
const wxUserInfo = {'openId':openid}
if (userinfo !== undefined){
if ('user_info' in userinfo){
wxUserInfo = JSON.parse(userinfo.user_info)
}
}
此代码修改已经验证。
在测试wafer2-node-sdk 1.4.1版本时发现,初次登录时的微信昵称会一直存在数据库里,后续即使更改了微信昵称,进行qcloud.login()/qcloud.loginWithCode()操作都不能更新用户信息。
更新 1.4.0 之后 qcloud.request 参数 login: false 时 skey 会报错:
{"code":-1,"error":"ERR_SKEY_INVALID"}
已经调过登录接口的。
API 文档里的
const qcloud = require('qcloud-weapp-server-sdk')(options)
应该是
const qcloud = require('wafer-node-sdk')(options)
新旧版混在一起,看得有点懵
当前好像folder的配置是静态的吧,是在config.js中提前配置好的。
根据新规则,开发环境,默认获取不了getUserInfo,所以需要调整demo代码。
还有就是我尝试自己在sdk改代码,上传node_modules,没有生效
11:23:27.482 response.js:20 Catch Error: Error: ERR_SKEY_INVALID
at validation (/data/release/node-weapp-demo/node_modules/wafer-node-sdk/lib/auth/index.js:91:22)
at validationMiddleware (/data/release/node-weapp-demo/node_modules/wafer-node-sdk/lib/auth/index.js:139:12)
at dispatch (/data/release/node-weapp-demo/node_modules/koa-router/node_modules/koa-compose/index.js:44:32)
at next (/data/release/node-weapp-demo/node_modules/koa-router/node_modules/koa-compose/index.js:45:18)
at /data/release/node-weapp-demo/node_modules/koa-router/lib/router.js:346:16
at dispatch (/data/release/node-weapp-demo/node_modules/koa-router/node_modules/koa-compose/index.js:44:32)
at /data/release/node-weapp-demo/node_modules/koa-router/node_modules/koa-compose/index.js:36:12
at dispatch (/data/release/node-weapp-demo/node_modules/koa-router/lib/router.js:351:31)
at dispatch (/data/release/node-weapp-demo/node_modules/koa-compose/index.js:42:32)
at parseBody.then.body (/data/release/node-weapp-demo/node_modules/koa-bodyparser/index.js:74:14)
VM300:2 Failed to load image http://qcloudtest-1255944088.cosgz.myqcloud.com/1516349296633-r1t_vQJHM.jpg
the server responded with a status of 403 (HTTP/1.1 403 Forbidden)
From server 14.119.113.25
if (code && !encryptedData && !iv) {
return getSessionKey(code).then(pkg => {
const { openid, session_key } = pkg
// 生成 3rd_session
const skey = sha1(session_key)
return AuthDbService.getUserInfoByOpenId(openid).then(userinfo => {
const wxUserInfo = JSON.parse(userinfo.user_info)
return AuthDbService.saveUserInfo(wxUserInfo, skey, session_key)
.then(userinfo => ({
loginState: LOGIN_STATE.SUCCESS,
userinfo: {
userinfo: wxUserInfo,
skey: userinfo.skey
}
}))
})
})
}
代码中getUserInfoByOpenId()先于saveUserInfo()使用,那么其中getUserInfoByOpenId()返回的userinfo很可能是undefined,我就遇到这种情况。
有两种模板消息发至服务号,都含有昵称字段。
其中一种模板消息的昵称从数据库里取的,在服务号收到消息里昵称显示正常。
另一种模板消息的昵称是从ctx.state.$wxInfo.userinfo里取的,如果用户昵称包含有表情的话,会有一定的概率出现乱码(黑色方块,中间是问号)。
如果在小程序解决方案里面会分配一个地址给你。按之前你在issues里面说的
tunnelServerUrl 填写 https://tunnel.ws.qcloud.la,tunnelSignatureKey 随机就行
我用demo测试点了链接,提示链接成功,点发送消息没反应。服务端也没有任何报错,请问是什么问题?
ps:开通了开发环境,但是没开通生产环境
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.