小伙伴们,小编在上一期中有讲到了微信小程序智慧商圈、微信支付快速积分到账小程序接入前准备,那么这期咱们来看看如何开发,由于小编是前端开发,后端不熟,所以这里就直接给小伙伴们抛一个官方的开发指引了:智慧商圈开发指引
开发指引中有java、PHP、go语言的开发讲解
那么我们直接来看下前端该如何配置吧。
- 接入指引
插件版本请选择最新版 >= 1.3.0(2021-03-29)
小程序基础库版本要求:1.9.6 以上 - 添加插件
微信公众平台-登录小程序-设置-插件管理-添加插件-搜索“商圈快速积分”-复制插件的AppID - 添加插件配置(引入插件包)
这里是参考微信小程序开发使用插件在小程序项目包中的app.json配置plugins插件版本号以及插件APPID
{
"pages": [
"pages/index/index",
],
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于XXX显示"
}
},
"plugins": {
"myPlugin": {
"version": "1.3.0",
"provider": "插件APPID"
}
},
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTextStyle": "black"
},
"style": "v2",
"sitemapLocation": "sitemap.json",
}
- 智慧商圈授权
这里要先准备好插件需要的字段
1、mch_id:商圈商户号
2、openid:用户openid,顾客授权时使用的小程序上的openid
所以这里我们就要拿微信支付里的商户号来,然后还要先获取用户openid,并且开发指引中表示需要在app.js中的onshow方法中调用插件接口所以这里小编就在app.js的onshow()这样来授权这个插件
onShow(){
var that = this;
wx.getLocation({
type: 'wgs84',
isHighAccuracy:true,
success (res) {
console.log("授权位置",res)
}
})
wx.login({
success: res => {
console.log("wx.login::",res)
var data = {
code:res.code
}
com.Get('getCode',data).then(res=>{
console.log("getcode获取",res)
var myPluginInterface = requirePlugin('myPlugin');
myPluginInterface.getAuthStatus(res.data.data.data.openid,'mch_id').then(res => {
console.log("智慧商圈是否授权",res)
})
myPluginInterface.getLocation(res.data.data.data.openid).then(shoppingRes => {
console.log("智慧商圈::",shoppingRes)
})
that.globalData.userData = res.data.data.data;
})
}
})
},
- 页面实现
当用户点击授权微信积分跳转商圈快速积分页
wxml:
<view class="container-1-3-right" bindtap="gotoZHSQ">
<image src="../../../image/index/selfP/4.png"></image>
授权微信积分
</view>
js:
// 前往智慧商圈
gotoZHSQ(){
var that = this;
console.log("前往智慧商圈 我的信息",getApp().globalData.userInfo)
wx.navigateTo({
url:'plugin://myPlugin/index?openid='+getApp().globalData.userInfo.openid+'&mch_id=mch_id'
})
},
这样就可以实现打开授权商圈快速积分啦!下面小编附上一些开发中会遇到的报错码及解决方案
微信智慧支付即积分常见问题解决办法:https://docs.qq.com/sheet/DTm9VVHdsYWJwUWN4?tab=BB08J2&_t=1606291263063&groupUin=ROr9T6%252FJKCz65ty37a8I2w%253D%253D&tdsourcetag=s_macqq_aiomsg&jumpuin=1476982312
好啦~这就是小编开发微信智慧商圈时候遇到的问题,感兴趣的小伙伴可以和我聊聊哦,如果您有不同的开发方法,麻烦也跟小编分享一下哦!