Home > Article > WeChat Applet > About the mall development of WeChat mini programs (ecshop)
This article mainly introduces relevant information about simple examples of WeChat mini program mall development (ecshop). Friends in need can refer to it
Mini programs are very popular recently, so our company has also docked with the ecshop platform Mini program
Includes complete user system and shopping system
User system: delivery address, order management, message management, coupon management, etc.
Shopping system payment for shopping Car management, WeChat payment, etc.
1: Acquisition and caching of user information after scanning the QR code of the mini program
Two APIs are required to obtain user informationwx.login(OBJECT)
wx.getUserInfo(OBJECT)
wx.setStorageSync(KEY,DATA)
//app.js App({ onLaunch: function() { }, getUserInfo: function (cb) { var that = this if (this.globalData.userInfo) { typeof cb == "function" && cb(this.globalData.userInfo) } else { //调用登录接口 wx.login({ success: function (res) { if (res.code) { var userid = wx.getStorageSync('scuserid') var sc_session_id = wx.getStorageSync('sc_session_id') var openid = wx.getStorageSync('sc_session_id') if(!userid){ wx.request({ url: 'xxxx/data.php?action=sendCode', data: { code: res.code, }, success: function (res) { //console.log(res) var status = res.data.status if(status == 1){ wx.showToast({ title: res.data.message, icon: 'success', duration: 2000 }) }else if(status == 2){ var scuserid = res.data.userid if(scuserid > 0){ //缓存user_id wx.setStorageSync('scuserid', scuserid) wx.setStorageSync('openid', res.data.openid) wx.setStorageSync('sc_session_id', res.data.session_id) } }else{ //缓存session_id wx.setStorageSync('openid', res.data.openid) wx.setStorageSync('sc_session_id', res.data.session_id) //获取用户信息 wx.getUserInfo({ success: function (res) { that.globalData.userInfo = res.userInfo typeof cb == "function" && cb(that.globalData.userInfo) //console.log(res); wx.request({ url: 'xxxx/data.php?action=saveUserInfo', data: { userinfo: res.userInfo, openid: wx.getStorageSync('openid'), }, success: function (res) { //console.log(res.data) var status = res.data.status if(status == 1){ wx.showToast({ title: res.data.message, icon: 'success', duration: 2000 }) }else{ var scuserid = res.data.userid if(scuserid > 0){ //缓存user_id wx.setStorageSync('scuserid', scuserid) } } } }) } }) } } }) } } } }) } }, globalData: { userInfo: null } })
2: Obtain WeChat user information and how to cache user information
To obtain the user’s geographical information, you need to usewx.getLocation(OBJECT)
//获取纬度,经度 wx.getLocation({ type: 'wgs84', success: function (res) { var latitude = res.latitude var longitude = res.longitude wx.request({ url: 'http://XXXXXX/data.php?action=get_dq', data: { latitude: latitude, longitude: longitude }, headers: { 'Content-Type': 'application/json' }, success: function (res) { //console.log(res.data) var province = res.data.result.addressComponent.province //console.log(province) var city = res.data.result.addressComponent.city var district = res.data.result.addressComponent.district var diqu = province+city+district //缓存当前所在地区 wx.setStorageSync('dq_diqu', diqu) wx.setStorageSync('dq_district', district) } }) } }) if($act=="get_dq"){ //获取当然城市 //http://api.map.baidu.com/geocoder/v2/?ak=327381a342077a8f3d584251b811cce5&callback=renderReverse&location=30.593099,114.305393&output=json //纬度 $latitude = $_REQUEST['latitude']; //经度 $longitude = $_REQUEST['longitude']; $url = 'http://api.map.baidu.com/geocoder/v2/?ak=327381a342077a8f3d584251b811cce5&location='.$latitude.','.$longitude.'&output=json'; $result = file_get_contents($url); exit($result); }The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please Follow PHP Chinese website! Related recommendations:
Simple example of shopping cart in WeChat mini program
How to implement Meituan menu in WeChat mini program
The above is the detailed content of About the mall development of WeChat mini programs (ecshop). For more information, please follow other related articles on the PHP Chinese website!