效果展示
文档
https://mp.weixin.qq.com/wxopen/plugindevdoc?appid=wxfab2bf944bfc4da6&token=1213946737&lang=zh_CN
1、首先根据文档把需要申请的插件及开通的功能进行开通
2、审和通过后,添加插件
在配置文件 新微信原生小程序在 app.js中,uniapp在 mainfest.json 中 添加插件
"myPlugin": {
"version": "2.5.5",
"provider": "wxfab2bf944bfc4da6"
}
3、使用
1、注意在使用这个插件的时候 需要配合获取位置函数getLocation一起使用
所以 在 进入页面的时候 在app.vue中
onShow: function() {
var myPluginInterface = requirePlugin('myPlugin');
let openId = uni.getStorageSync("openId")
myPluginInterface.getLocation(openId).then(res => {
})
},
*注:使用该API 需要在配置中先声明权限
"permission" : {
"scope.userLocation" : {
"desc" : "获取当前城市"
}
},
2、可以在需要的界面中添加click点击函数
其中openid取登录时返回的openid,商户id在微信商户管理后台中查看(建议存储在数据库,通过接口返回,我这是this.store.state.homex.smartBusDisType)
字段说明
goSq(){
var myPluginInterface = requirePlugin('myPlugin');
let openId = uni.getStorageSync("openId")//获取openid
//openid 和 mchid 换成自己的
myPluginInterface.getAuthStatus(openId,this.store.state.homex.smartBusDisType).then(res => {
if(res.return_code == 0){
uni.navigateTo({
url:`plugin://myPlugin/index?openid=${openId}&mch_id=${store.state.homex.smartBusDisType}&member_status=1`
})
}
})
}
member_status我传了1,因为在我的程序中已经提前校验过会员状态了
另外 myPluginInterface.getAuthStatus api 的status可以通过返回的值来进行后续的处理操作
例如 status:0 , 代表未开通 ,status:1 , 代表未已开通,status:2,代表开通后关闭又开通
到这一步智慧商圈的前端部分功能就实现了,后续需要后端根据文档对其中展示的数据进行对接