微信小程序端
登录界面
.wxml
<view class="page-body">
<text>手机号</text>
<input bindinput="bindPhone" type="number" maxlength="11" placeholder="最大输入长度为11" />
<text>密码<text bindtap="message">点击获取验证码</text></text>
<input bindinput="bindCode" password type="text" placeholder="请输入密码" />
</view>
<button bindtap="login">登录</button>
.js
// pages/login/login.js
Page({
/**
* 页面的初始数据
*/
data: {
isTrue:false,
phone:"",
code:""
},
bindPhone(e){
this.setData({phone:e.detail.value});
},
bindCode(e){
this.setData({code:e.detail.value});
},
message(){
if (this.data.phone.lenth!=11){
wx.showToast({
title: '长度错误',
icon:"none"
})
return ;
}
var reg=/^(1[3|4|5|6|7|8|9])\d{9}$/;
if(!reg.test(this.data.phone)){
wx.showToast({
title: '格式错误',
icon:"none"
})
return ;
}
wx.request({
url: 'http://(ip:端口)/message',
data: {phone:this.data.phone},
method: "POST",
success:(res)=>{
console.log(res);
}
})
},
login:function(){
var that=this;
wx.request({
url: 'http://(ip:端口)/login',
data: {phone:this.data.phone,code:this.data.code},
method: "POST",
success:(result) => {
that.setData({isTrue:result.data})
if( that.data.isTrue=="True")
wx.navigateTo({
url: '/pages/uploader/uploader',
})
else{
wx.showModal({
cancelColor: 'cancelColor',
title:"密码错误或账号不存在"
})
// wx.showToast({
// title: '密码错误或账号不存在',
// icon:"error"
// })
}
},
fail: (res) => {},
complete: (res) => {},
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
}
})
后端服务接口
@app.route('/login', methods=['POST'])
def weixin():
phone=request.get_json()['phone']
code=request.get_json()['code']
conn=pymysql.connect(local_infile='127.0.0.1',user='root',password='Hello')
cursor=conn.cursor()
cursor.execute('select * from designdb.userinfo;')
result=cursor.fetchall()
print(phone,code)
cursor.close()
conn.commit()
conn.close()
for some in result:
print(some[0],some[1])
if phone==some[0] and code==some[1]:
print('yes')
return 'True'
print('no')
return 'False'
这里采用数据库存储信息的方式,在服务端验证账号密码
数据库组成
uploader页面
.wxml
<button type="warn" bindtap="uploadimg">上传图片</button>
<button bindtap="pretectpic">开始运行</button>
<view class="container" bindtap="viewimages">
<image wx:for="{{imagelist}}" src="{{item}}"></image>
</view>
<image src="{{imgs}}" ></image>
.js
// pages/goods/goods.js
Page({
/**
* 页面的初始数据
*/
data: {
datalist:["goods1","goods2","goods3","goods4","goods5"],
userinfo:{name:"xiaoming",
age:18},
// imagelist:["/images/icon1.png","/images/icon2.png","/images/icon3.png","/images/icon1.png",]
imagelist:"",
imgs:""
},
uploadimg:function(){
var that=this;
wx.chooseImage({
count: 1,
sizeType:["original","compressed"],
sourceType:["album","camera"],
success:function(res){
const tempFilePaths=res.tempFilePaths[0];
console.log(tempFilePaths)
that.setData({imagelist:res.tempFilePaths})
wx.cloud.uploadFile({
cloudPath:'storage/pic3',
filePath:tempFilePaths
})
wx.showModal({
cancelColor: 'cancelColor',
title:"上传成功"
})
},fail(res){
console.log("fail"+res);
},complete(res){
console.log("complete"+res);
}
})
},
pretectpic(){
var that =this;
wx.request({
url: 'http://(ip:端口)/uploader',
data: {domin:"(图片在云存储的位置)"},
method: "POST",
success: (res) => {
if (res.data) {
base64Data = wx.arrayBufferToBase64(wx.base64ToArrayBuffer(res.data));
/// 拼接请求头,data格式可以为image/png或者image/jpeg等,看需求
const base64ImgUrl = "data:image/png;base64," + base64Data;
/// 刷新数据
that.setData({
imgs : base64ImgUrl
})
}
}
})
},
viewimages(){
var that=this;
wx.previewImage({
current:"",
urls: that.data.imagelist
})
},
onLoad(options) {
}
})
后端接口
@app.route('/uploader',methods=['POST'])
def uploader():
url=request.get_json()['domin']
resp = requests.get(url)
time.sleep(0.5)
with open('inputs/result.jpg', mode='wb') as f:
f.write(resp.content)
f.close()
os.system("(待执行的python指令)")
return return_img_stream('results/result_out.jpg')
推理接口
Real-ESRGAN-master
Real-ESRGAN-master项目地址
使用方法
python后端
利用flask搭建的服务后端
import json
import os
import time
import requests
from flask import Flask
from flask import request
from flask import jsonify
import pymysql
# from flask_cors import CORS
from gevent import pywsgi
# from geventwebsocket.handler import WebSocketHandler
import queue
app = Flask(__name__)
app.config['DEBUG'] = True
def return_img_stream(img_local_path):
import base64
with open(img_local_path, 'rb') as img_f:
img_stream = img_f.read()
img_stream = base64.b64encode(img_stream).decode()
return img_stream
@app.route('/func3',methods=['POST'])
def message():
url=request.get_json()['domin']
resp = requests.get(url)
time.sleep(0.5)
with open('inputs/result.jpg', mode='wb') as f:
f.write(resp.content)
f.close()
os.system("(待执行的python指令)")
return return_img_stream('results/result_out.jpg')
@app.route('/login', methods=['POST'])
def weixin():
phone=request.get_json()['phone']
code=request.get_json()['code']
conn=pymysql.connect(local_infile='127.0.0.1',user='',password='')
cursor=conn.cursor()
cursor.execute('select * from designdb.userinfo;')
result=cursor.fetchall()
print(phone,code)
cursor.close()
conn.commit()
conn.close()
for some in result:
print(some[0],some[1])
if phone==some[0] and code==some[1]:
print('yes')
return 'True'
print('no')
return 'False'
if __name__ == "__main__":
# app.config['SECRET_KEY'] = '!QAZ2wsx'
# http_server = pywsgi.WSGIServer(('', 5007), app, keyfile='qiangzhou.key',certfile='qiangzhou.crt', handler_class = WebSocketHandler)
# http_server.serve_forever()
app.run("0.0.0.0",port=4000)