Coder Social home page Coder Social logo

jasonboy / wechat-jssdk Goto Github PK

View Code? Open in Web Editor NEW
720.0 26.0 93.0 4.22 MB

🐧微信JSSDK与NodeJS及Web端集成 WeChat JSSDK integration with NodeJS & Web

License: MIT License

JavaScript 100.00%
wechat wechat-jssdk oauth wechat-oauth nodejs weixin weixin-jssdk wechat-mini-program

wechat-jssdk's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wechat-jssdk's Issues

usage clarification

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.

你好,希望可以自定义scope,这样的话, 非公众号appid也可以使用这个package了

你好,@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)

vue无法使用fs

hi,配置中有paymentCertificatePfx: fs.readFileSync(path.join(process.cwd(), 'cert/apiclient_cert.p12')),而在vue-cli中无法引入fs,请问有什么解决方案?

能支持proxy吗?

unifiedOrder之类的函数必须在服务器上调用,调试时非常麻烦,能够增加proxy设置可以轻松很多

卡券问题

现在getCardExt 只有outer_str参数,我需要outer_id,能加上吗

invalid credential, access_token is invalid or not latest hint

现在有极小概率出现这个提示,可能是其他地方调用了access_token,导致我们自己的过期了,我目前就用了co-wechat-api和wechat-jssdk。
过期后我可能要等两个小时候业务才会恢复。能麻烦加入一个重新获取的机制吗,比如收到40001错误,就重新获取access_token,然后重新请求。

TypeError: Wechat is not a constructor

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/www

available 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

小程序支付签名问题

Payment.js generateChooseWXPayInfo函数 appId: this.wechatConfig.appId
这个会appid是我的公众号appid,在miniProgram下还有一个appid这个是小程序的
那么,我在生成wx.requestPayment所需内容的时候签名就有问题了。

请问,现在支付是不是还没有完全适配小程序?

Cannot read property 'findOneAndUpdate' of undefined

系统: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)

调用语法糖callWechatApi时报错,急急急

版本:"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);
image

这是什么情况

Why the callback is not run

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!'.

请教OAuth如何使用

@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后跳转吗?

Use stubs for quick unit tests

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.

success回调不起作用?

const wxObj = new WechatJSSDK({
            ...wxConf,
            'success': () => {
              console.log(wxObj.wx, '????')
            },
          })
          console.error(wxObj.wx)
          setTimeout(() => console.error(wxObj.wx, '~!!!!!!!'), 1500)

sucess回调里面的没有被调用,
只有settimeout可以取到wxObj.wx

can't use jssdk in react

用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')用的时候浏览器出错

浏览器端能不能有个ready方法等待核心库的加载?很苦恼~

刚new完WechatJSSDK,并不能马上获取到window.wx,那么自然而然使用里面的callWechatApi方法通通报错!!,看了源码才发现new的过程中还有一个loadScript方法在异步加载核心库,这下蛋疼了,没有对外提供一个ready方法让我们等待这个异步,那么何时使用wx的方法,很苦恼,计时器都不那么好用,希望能提供一个该接口(考虑做个事件触发器单独触发一个ready,或者构造器里面直接弄个回调也可以简单粗暴好用)。谢谢

支付请求95%的几率出现Z_DATA_ERROR:unknown compression method

如题,之前都是好好的,不知道为何从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确实有问题

使用Oauth时出现的问题

你好!

我按照readme配置了微信公众平台,并修改了index.js后,点击Oauth一直有问题。步骤是:

配置:

  1. 将我的微信号在公众平台注册了一个测试账号,在接下来的页面中按说明做了配置。token服务器在公网上(配置成类似:http://1.2.3.4:12345),验证通过。

config_wechat_server

2. 使用这个页面的token,appid,appsecrect配置到index.js上去. 3. "wechatRedirectUrl"没有修改("http://127.0.0.1/oauth") 4. 启动后,使用微信web开发者工具访问127.0.0.1,各种验证的load是ok的:

22

5. 然后访问Oauth页面,却进入页面:

3

在进入这个页面前,网页console有GET 一个url失败(ERR_BLOCKED_BY_CLIENT)的错误。

请问以上配置步骤是否有问题?有哪里做得不对吗?

非常感谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.