wx-微信公众号-静默登陆授权

介绍

功能: 支持微信/支付宝网页静默授权
为什么需要线上html
因为在开发环境的时候,是本地服务http://localhost:8080,但是微信需要JS接口安全域名.

配置信息

  1. 先登录微信公众平台进入“公众号设置”的“功能设置”里填写“网页授权域名”
  2. 然后把 html 文件放到服务器上, 安全域名指向这个html
  3. 在 vue 环境配置文件(.env.development、.env.production),中配置以下参数
    1. VUE_APP_WX_GET_CODE_DOMAIN = ‘第二步的html文件的线上地址’
    2. VUE_APP_APP_ID = ‘微信/支付宝的appid’
  4. 使用方法:
    1. 直接调取 util 文件中的 getAuthorCode 方法
    2. 调取完后,就可以在地址栏中,看到那个 code 了 (获取code的时候,可以使用这个方法 onGetRequest().code )

代码信息

授权文件


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>授权code</title>
</head>
<body>
  
</body>
</html>
<script>
(function () {
     
     
  var tools = {
     
     
    getParamer: function (key) {
     
     
      var map = this.getSearch();
      return map[key];
    },
    getSearch: function () {
     
     
      var search = window.location.search;
      return this.getSearchByStr(search);
    },
    getSearchByStr: function 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值