接口
Route::middleware('auth:api')->prefix('index')->middleware('throttle:1000,1')->group(function (){
Route::get('ShowIn',[\App\Http\Controllers\show\index::class,'index']);
Route::get('ShowSel',[\App\Http\Controllers\show\index::class,'sel']);
Route::get('ShowselShow',[\App\Http\Controllers\show\index::class,'selShow']);
Route::get('InControllerCreate',[\App\Http\Controllers\show\index::class,'InControllerCreate']);
Route::get('ShowInSel',[\App\Http\Controllers\show\Showin::class,'sel']);
Route::get('ShowInDel',[\App\Http\Controllers\show\Showin::class,'del']);
});
小程序获取登录
<view class="container">
<view class="userinfo">
<block wx:if="{
{!hasUserInfo}}">
<button wx:if="{
{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取头像昵称 </button>
<button wx:else open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
</block>
<block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{
{userInfo.avatarUrl}}" mode="cover"></image>
<text class="userinfo-nickname">{
{userInfo.nickName}}</text>
</block>
</view>
</view>
小程序登录页面js
var util = require('../../utils/util');
Page({
data: {
userInfo: {},
hasUserInfo: false,
canIUseGetUserProfile: false,
avatarUrl:'',
nickName:''
},
onLoad() {
var thime=util.formatTime(new Date());
console.log(thime);
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
},
getUserProfile(e) {
wx.getUserProfile({
desc: '勇敢妞妞不怕困难',
success:(res)=>{
this.setData({
avatarUrl:res.userInfo.avatarUrl,
nickName:res.userInfo.nickName
})
wx.login({
success: (res) =>{
if (res.code) {
// 发起网络请求
wx.request({
url: 'http://www.ceshi.com/index/ShowIn',
data: {
code: res.code,
avatarUrl: this.data.avatarUrl,
nickName: this.data.nickName
},
success:function(res){
console.log(res.data.openid);
wx.setStorage({
key:"openid",
data:res.data.openid
})
wx.navigateTo({
url: '/pages/home/home',
})
},
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
}
})
},
navigate