当前位置:网站首页>Wechat applet (authorized login of TP5)
Wechat applet (authorized login of TP5)
2022-06-11 06:16:00 【Results of persistence and effort】
HTML page
<button open-type="getUserInfo" bindtap="login" wx:if="{
{ showThis }}"> Authorized login </button>
<image src="/pages/image/2.png" style="width: 150rpx;height: 150rpx;padding-left: 300rpx;" wx:if="{
{ pic }}"></image>
<text>\r\n</text>
<text wx:if="{
{ pic }}" style="padding-left: 330rpx;"> full name </text>
JS: commentary
// pages/login/login.js
Page({
// Initial data of the page
data: {
showThis:true,
pic:false
},
onLoad: function (options) {
},
login(){
// adopt wx.getUserProfile The authorization box pops up
let that = this;
wx.getUserProfile({
desc: 'desc',
success:res=>{
// adopt wx.login obtain code
wx.login({
success:d=>{
let code = d.code;
// send out ajax request , And will code Carry the past
wx.request({
url: 'http://www.weekpic.com/loginDo',
data:{code:code},
success:function(r){
if(r.data.code==200)
{
let id=r.data.data.id;
let token=r.data.data.token;
wx.setStorage({
key:"uid",
data:id
})
that.setData({
showThis:false,
pic:true
})
wx.setStorage({
key:"token",
data:token
})
wx.showToast({
title: ' Login successful !',
})
wx.switchTab({
url: '/pages/type/type',
})
}
}
})
}
})
},
fail:res=>{
wx.showToast({
title: " privilege grant failed ",
})
}
})
}
})
php commentary :
public function loginDo(Request $request)
{
$code=$request->get('code');
$SECRET="";//SECRET
$APPID="";//appid
$url="https://api.weixin.qq.com/sns/jscode2session?appid=$APPID&secret=$SECRET&js_code=$code&grant_type=authorization_code";
$url=json_decode(file_get_contents($url,true),true);
$findRes=login::where('appid',$APPID)->find();
if($findRes)
{
$token=Token::createToken(1);
$data=[
'token'=>$token,
'id'=>$findRes['id']
];
return ['code'=>200,'msg'=>'success','data'=>$data];
}
$createRes=login::create(['appid'=>$APPID]);
if($createRes)
{
// $token=Token::createToken($createRes['id']);
$data=[
'token'=>$token,
'id'=>$createRes['id']
];
return ['code'=>200,'msg'=>'success','data'=>$data];
}
}边栏推荐
- View controller and navigation mode
- JIRA software annual summary: release of 12 important functions
- Servlet
- Cocoatouch framework and building application interface
- Notes sur les questions d'entrevue de la FPGA (IV) - - détecteur de séquence, Code gris dans le domaine de l'horloge croisée, opération de ping - pong, réduction de la perte statique et dynamique, err
- [daily exercises] 1 Sum of two numbers
- Excellent practice | how to avoid a bloody case caused by a line of wrong code?
- 亚马逊、速卖通、Lazada、虾皮平台在用911+VM的环境可以进行产号、养号、补单等操作吗?
- Sword finger offer 32: print binary tree from top to bottom
- Global case | how Capgemini connects global product teams through JIRA software and confluence
猜你喜欢

FPGA interview notes (IV) -- sequence detector, gray code in cross clock domain, ping-pong operation, static and dynamic loss reduction, fixed-point lossless error, recovery time and removal time

FPGA interview notes (II) -- synchronous asynchronous D flip-flop, static and dynamic timing analysis, frequency division design, retiming

What is a planning BOM?

ThymeleafEngine模板引擎

Sword finger offer 50: the first character that appears only once

Deployment of Flink

Jenkins voucher management

Matlab实现均值滤波与FPGA进行对比,并采用modelsim波形仿真

Review XML and JSON

Simple understanding of pseudo elements before and after
随机推荐
CCF 2013 12-5 I‘m stuck
Sqli-libs post injection question 11-17 actual combat
Topic collection of FIFO minimum depth calculation
FMT package usage of go and string formatting
Sword finger offer 04: find in 2D array
The classification effect of converting video classification data set to picture classification data set on vgg16
Shuffleerror:error in shuffle in fetcher solution
call和apply和bind的区别
Basic use of BufferedReader and bufferedwriter
[usual practice] explore the insertion position
FPGA interview notes (IV) -- sequence detector, gray code in cross clock domain, ping-pong operation, static and dynamic loss reduction, fixed-point lossless error, recovery time and removal time
[IOS development interview] operating system learning notes
autojs,读取一行删除一行,停止自己外的脚本
The difference between call and apply and bind
Completabilefuture asynchronous task choreography usage and explanation
FPGA Design -- ping pong operation implementation and Modelsim simulation
Servlet
Servlet
跨境电商测评自养号团队应该怎么做?
Use meshlab to sample the point cloud of CAD model and display it in PCL