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) {
-
//发起网络请求获得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);
-
}
|