微信小程序/公众号

目录

H5唤醒小程序

微信公众号-H5微信登录授权


H5唤醒小程序

官方API参考:

        获取Token    获取urlscheme

其他文章参考:

        唤醒小程序

const appid = '' // appid
const secret = '' // secret
const granttype = 'client_credential' // 固定值

// 获取Token
axios.get(`https://api.weixin.qq.com/cgi-bin/token?grant_type=${granttype}&appid=${appid}&secret=${secret}`).then(res => {
    // 获取 urlscheme
    axios.post(`https://api.weixin.qq.com/wxa/generatescheme?access_token=${(res.data as { 'access_token': string }).access_token}`, {
        jump_wxa: {
            path: 'pages/home/home'
        }
    }).then(response => {
        // 唤醒小程序
        window.open((response.data as { 'openlink': string }).openlink) // weixin://xxxxxxxxx
    }).catch(() => { /* */ })
}).catch(() => { /* */ })

最终效果:

踩坑:

        第二步生成urlscheme时,必须填写path参数,即唤醒小程序要跳转的页面。

        H5唤醒小程序只支持企业小程序,个人小程序无权限生成urlscheme。

        H5唤醒小程序只能在微信端打开,因为生成的urlscheme是微信生态中的连接。

        调接口过程最好也有必要做在服务端,一是为了安全,二是调接口时的跨域问题。

微信公众号-H5微信登录授权

        在微信公众号中,跳转到第三方H5网站,第三方H5网站可以获取微信用户信息。微信公众号网页授权https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html        微信公众平台中设置要授权的第三方H5网站,只有设置了,第三方H5网站才有权限获取微信用户信息。

设置与开发---->公众号设置---->功能设置---->网页授权域名

 

  • 步骤一:微信用户授权,获取code
https://open.weixin.qq.com/connect/oauth2/authorize?appid=微信公众号appid&redirect_uri=要跳转的H5网站&response_type=code&scope=snsapi_userinfo#wechat_redirect

  • 步骤二:通过第一步获取的code,来获取access_token 和 openid
https://api.weixin.qq.com/sns/oauth2/access_token?appid=微信公众号appid&secret=微信公众号的secret&code=第一步获取的code&grant_type=authorization_code

  •  步骤三:获取用户信息
https://api.weixin.qq.com/sns/userinfo?access_token=第二步获取的Token&openid=第二步获取的openid&lang=zh_CN

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

L-R-T

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值