0.6.11 • Published 1 year ago

node-weixin-media-platform-api v0.6.11

Weekly downloads
61
License
ISC
Repository
-
Last release
1 year ago

微信公众平台文档: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140839 getProfile(openId, callback)

getMPQRCode(sceneId, (error, result) => { // result is a qrcode buffer })

输入: openId 输出:

{
   "subscribe": 1, 
   "openid": "o6_bmjrPTlm6_2sgVt7hMZOPfL2M", 
   "nickname": "Band", 
   "sex": 1, 
   "language": "zh_CN", 
   "city": "广州", 
   "province": "广东", 
   "country": "中国", 
   "headimgurl":  "http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4
eMsv84eavHiaiceqxibJxCfHe/0",
  "subscribe_time": 1382694957,
  "unionid": " o6_bmasdasdsad6_2sgVt7hMZOPfL"
  "remark": "",
  "groupid": 0,
  "tagid_list":[128,2]
}

微信 JS 接口签名校验工具 https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign

vue前端使用如下方式

router.beforeEach((to, from, next) => {
  // 每次在切换路由之前要看下有没有微信授权
  router.app.$getAsync('/login').then(data => {
    if (data.data.data.isLoggedIn) {
      next()
    } else {
      let backUrl = encodeURIComponent(`${Conf.frontDomain}${to.path}`)
      window.location.href = `${Conf.apiDomain}/wxAuth?backUrl=${backUrl}`
    }
  })
})

后端使用如下方式跳转

router.get('/wxAuth', weixinSdk.auth, (req, res) => {
	let openId = req.session.openId
	let redirectUrl = req.query.backUrl
  try {
    // 做用户setup的工作
	  let {openId, nickName, headImageUrl, sex} = req.session
	  const [user, created] = await models.couponOrderUser.findOrCreate({
		  where:{
			  openId
		  }
	  })
	  req.session.userId = user.id
	  res.redirect(redirectUrl)
  } catch (e) {
	  res.redirect(redirectUrl)
  }
})
0.6.11

1 year ago

0.6.10

3 years ago

0.6.9

3 years ago

0.6.8

4 years ago

0.6.7

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.9

5 years ago

0.5.8

5 years ago

0.5.7

5 years ago

0.5.6

5 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.9

6 years ago

0.4.8

6 years ago

0.4.7

6 years ago

0.4.6

6 years ago

0.4.5

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.9

6 years ago

0.3.8

6 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.9

6 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago