项目作者: zjhch123

项目描述 :
Wechat service for configuration and authentication, 用于配置、鉴权的微信服务
高级语言: JavaScript
项目地址: git://github.com/zjhch123/wechat-service.git
创建时间: 2020-01-17T15:37:56Z
项目社区:https://github.com/zjhch123/wechat-service

开源协议:

下载


badge

Usage

Please add your server IP and domain to the whitelist in the Wechat Official Accounts Platform and set your server url in the config/prod.js at first.

You should create the prod.js in config file and set appid and appsecret in it.

wxShare

Init

  1. <script>
  2. window.wxShareConfig = {
  3. title: 'xxx', // default is document.title
  4. desc: 'xxx', // default is ''
  5. imgUrl: 'xxx', // default is page icon
  6. link: 'xxx', // default is window.location.href,
  7. callback: () => {}, // default is () => {}
  8. }
  9. </script>
  10. <script src="{service_path}/wxShare"></script>

Reset share information

  1. <script>
  2. // reset the share config
  3. window.wxShare.setShareData({
  4. title: 'xxx',
  5. desc: 'xxx',
  6. imgUrl: 'xxx',
  7. link: 'xxx',
  8. callback: () => {},
  9. })
  10. </script>

wxAuth

Please set the auth.services in the config/prod.js at first.

Redirect to {serverPath}/wxAuth?redirect_uri={}&error_uri={}&service_id={}, server will redirect user to the wechat auth page.

service_id is required. Server will post the user information to the service.

redirect_uri is required, when auth and post user information successfully, the visitor will be redirected to the redirect_uri with search parameters appid and access_token.

error_uri is optional, default value is equal to redirect_uri, Server will redirect user to error_uri if there has any error.

User information

  1. {
  2. "openid": "openId",
  3. "access_token": "123abc",
  4. "nickname":"Nickname",
  5. "sex": 1,
  6. "language": "zh_CN",
  7. "city": "杭州",
  8. "province": "浙江",
  9. "country": "中国",
  10. "headimgurl": "user head img url",
  11. "privilege": []
  12. }

wxConfig

  1. window.wxConfig = {
  2. jsApiList: ['', ''],
  3. readyCallback: () => {
  4. wx.updateAppMessageShareData(xxxx)
  5. }
  6. }