1、composer下載thinkphp5
composer create-project topthink/think [你的目錄名] --prefer-dist
2、composer下載easywechat
composer require hooklife/thinkphp5-wechat
3、配置好小程序的appid和appsercret,還有證書
第一步:
獲取用戶的openid
小程序代碼
-
//app.js
-
App({
-
onLaunch: function() {
-
wx.login({
-
success: function (res) {
-
if (res.code) {
-
//發(fā)起網絡請求獲得openid
-
wx.request({
-
url: 'https://xxxxxxxx/index/on_login/index',
-
data: {
-
code: res.code
-
},
-
success:function(res){
-
//console.log(res.data.openid)
-
that.globalData.openId = res.data.openid
-
},
-
fail:function(e){
-
console.log(e);
-
}
|