使用uniapp开发微信小程序,小程序内嵌uniapp开发的H5项目,在此H5项目中使用微信小程序JSSDK

1.注册微信公众号,配置网站域名,获取密钥和appId

2.安装JSSDK,并且导入项目中

npm install weixin-js-sdk --save
import wx from 'weixin-js-sdk';

3.获取access_token,再通过access_token获取ticket

async getAccessToken() {
				const data = {
					appid: "",
					grant_type: "client_credential",
					secret: ''
				}
				const res = await getAccess_token(data);
				if (res && res.length > 0) {
					return res[1].data?.access_token;
				}

			},
	async getTicket() {
				const data = {
					access_token: await this.getAccessToken(),
					type: "jsapi"
				}
				const res = await getTicket(data);
				if (res && res.length > 0) {
					return res[1].data?.ticket
				}
			},

4.配置SDK参数

async configWechatSDK() {
				const timestamp = Date.now();
				const nonceStr = JSON.stringify(new Date());
				const signature = await this.getTicket();
				const config = {
					debug: true,
					appId: '',
					timestamp,
					nonceStr,
					signature,
					jsApiList: ['openLocation'] // 需要的JS接口列表   
				}
				wx.config(config);
				wx.ready(() => {
					console.log("jssdk加载成功!")

				})
				wx.error(() => {
					console.log("jssdk加载失败!")
				})
			},

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值