当前位置: 首页 > news >正文

微信网页授权获取用户openid

参考微信授权获取用户openId的方法和步骤 - 简书

设置与开发/公众号设置

1.设置网页授权回调域名(https) domain,下载MP_verify_RTxPGFBmE6RJmFFY.txt验证文件,设置80端口响应微信验证。

server {listen       80;server_name  domain;location /MP_verify_RTxPGFBmE6RJmFFY.txt {alias /home/path/MP_verify_RTxPGFBmE6RJmFFY.txt;autoindex on;}
}
    <aid="myLink"href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=appid&redirect_uri=https%3A%2F%2Fdomain%2Fdsp&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"></a>
//点击访问微信接口onMounted(() => {let router = useRouter();if (main.openId) {router.push("/login");} else {let a = document.getElementById("myLink");a!.addEventListener("click", function (event) {event.preventDefault();let targetLocation: any = this.getAttribute("href");window.location.href = targetLocation;});a?.click();}
});//回调重定向URL并获取code
//获取code后,请求以下链接获取access_token:
//https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
onMounted(async () => {//获取缓存openidif (window.location.href.split("code=")[1] && code.value == "") {var params = window.location.href.split("code=")[1].split("&")[0];code.value = params;let res = await getAccessToken({appid: "appid",secret: "secret",code: code.value,grant_type: "authorization_code",});openId.value = res.data.openid;setOpenId(res.data.openid);} else {router.push("/");}
});

server{listen 443 ssllocation / {root  /home/dsp;index index.html index.htm; #解决Failed to load module script: Expected a JavaScript module script but the server错误try_files $uri $uri/ /index.html;}
}


http://www.mrgr.cn/news/37454.html

相关文章:

  • Vue可视化大屏模板
  • 中级职称评审到底需要准备什么材料?
  • 关于液氮罐的液氮补给方式
  • ThreeJs创建球体
  • HTAP 数据库的应用场景:是否被过度夸大?
  • Go版数据结构 -【4.2 二叉搜索树】
  • 【JVM】垃圾释放方式:标记-清除、复制算法、标记-整理、分代回收
  • Windows环境部署Oracle 11g
  • 从0到1,数字媒体产业基地见证每一个创意的诞生与成长
  • (附代码)psutil实时监控脚本运行过程中消耗的资源
  • 如何选择高品质SD卡
  • 回溯九宫格质数c++
  • Therabody携手上海劳力士大师赛,全方位守护球员运动健康
  • 一文读懂Ingress-Nginx以及实践攻略
  • LeetCode[中等] 24.两两交换链表中的结点
  • CBC 模式安全问题
  • 【MATLAB代码】二维环境下的RSSI定位程序,自适应锚点数量,带图像输出、坐标输出、中文注释
  • 思想和认知,从身边的事情和从小经历就在培养。谁在起跑线!
  • 在 Windows8.1 下编译 Chromium (103.0.5060.68 之三)
  • 图文检索(3):On the Integration of Self-Attention and Convolution