Home  >  Article  >  WeChat Applet  >  About the mall development of WeChat mini programs (ecshop)

About the mall development of WeChat mini programs (ecshop)

不言
不言Original
2018-06-23 10:12:494745browse

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.







## I believe that many friends use ecshop as their own mall. Recently, mini programs have become popular again, so some people asked ecshop how to connect mini programs.


I happen to be developing a small program project to connect to ecshop recently, so I will share some of my development experience.

1: Acquisition and caching of user information after scanning the QR code of the mini program

Two APIs are required to obtain user information


wx.login(OBJECT)

Call the interface to obtain the login credentials (code) and then exchange the user login status information, including the user's unique identifier (openid) and this login The session key (session_key). Encryption and decryption of user data communication depends on the session key.

wx.getUserInfo(OBJECT)

To obtain user information, you need to call the wx.login interface first.

Get the api needed for cache


wx.setStorageSync(KEY,DATA)

Store data locally The specified key in the cache will overwrite the original content corresponding to the key. This is a synchronization interface.

The following is the specific example code:


We can write this paragraph in the public app.js page

//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 use


wx.getLocation(OBJECT)

Get the current geographical location and speed. When the user leaves the mini program, this interface cannot be called; when the user clicks "Show on top of chat", this interface can continue to be called.

Specific example code:

//获取纬度,经度 
 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn