本帖最后由 Aitlo 于 2022-4-20 18:43 编辑
首先:自行创建易如意网络验证站点:
1,登录易如意后台
1.1,选择应用管理-添加应用-后点击修改设置
1.2修改登录控制-选择卡密登录-设置安全控制(不加密,不签名)
1.3,设置应用控制-收费模式-点击确认是我操作-点击确认修改
2,服务器安装Python flask 和 requests (推荐Python 3.6以上版本)
2.1, pip install flask
2.2, pip install requests
flask_server.py 源码:
- import json
- import os
- import requests
- import time
- import uuid
- import hashlib
- from flask import Flask, request, make_response,send_from_directory,jsonify
- app = Flask(__name__)#ascii
- app.config['JSON_AS_ASCII'] = False
- privateKey = 'aitlo@cy..' //加密检验私钥
- publicKey = 'www.iaitlo.com' // 加密校验公钥
- Total_dict = {}
- @app.route('/login',methods=['POST'])
- def login():
- # 卡密登录验证
- lrjl_dict = request.form.to_dict()
- # 0,如果卡密已存在则先验证卡密和uuid
- if lrjl_dict['kami'] in Total_dict and lrjl_dict['uuid'] != Total_dict[lrjl_dict['kami']]['uuid']:
- return jsonify({'code':500,'msg':'卡密设备uudi不一致'})
- if lrjl_dict['kami'] in Total_dict and lrjl_dict['uuid'] == Total_dict[lrjl_dict['kami']]['uuid']:
- return heartbeat()
- # 1,先验证签名
- # - 验证成功 执行后面,不成功返回签名错误
- if request.method == 'POST':
- sign = f'{lrjl_dict["signTime"]}-{hashlib.md5(privateKey.encode("utf-8")).hexdigest()}-{hashlib.md5(publicKey.encode("utf-8")).hexdigest()}'.upper()
- server_sign = hashlib.md5(sign.encode('utf-8')).hexdigest()
- if lrjl_dict['sign'] != server_sign:
- return jsonify({'code':106,'mgs':'签名错误'})
- yry_params = {'kami':lrjl_dict['kami'],'t':time.time(),'app':lrjl_dict['app']}
-
- respones = requests.post('http://192.0.0.1/api.php?act=km_logon',params=yry_params)
- line_dict = respones.json()
- # print(line_dict,'易如意返回数据')
- if line_dict['msg'] == "卡密已使用" or line_dict['msg'] == "卡密已到期" or line_dict['msg'] == "卡密不存在":
- return jsonify(line_dict)
- elif line_dict['msg']['kami'] == lrjl_dict['kami']:
- # 登录验证通过
- if not lrjl_dict['kami'] in Total_dict:
- uuidStr = uuid.uuid4()
- Total_dict[lrjl_dict['kami']] = {'uuid':str(uuidStr),'vip':line_dict['msg']['vip']}
- return jsonify({'kami':lrjl_dict['kami'],'uuid':str(uuidStr),'vip':line_dict['msg']['vip']})
- if lrjl_dict['msg'] == '卡密已使用':
- return jsonify({'code': 500, 'msg': '卡密已使用'})
- return jsonify({'code':500,'msg':'未知错误请联系管理员'})
- @app.route('/unpinless',methods=['POST'])
- def unpinless():
- # 解绑设备
- lrjl_dict = request.form.to_dict()
- if lrjl_dict['kami'] in Total_dict and lrjl_dict['uuid'] == Total_dict[lrjl_dict['kami']]['uuid']:
- del Total_dict[lrjl_dict['kami']]
- return jsonify({'code':200,'msg':'已解绑设备','kami':lrjl_dict['kami']})
- else:
- return jsonify({'code':500,'msg':f'{lrjl_dict["kami"]}该卡密未绑定此设备,解绑失败!'})
- @app.route('/paycode',methods=['POST'])
- def payCode():
- # 卡密充值
- lrjl_dict = request.form.to_dict()
- res = requests.post(url='http://192.0.0.1/api.php?act=card',params=lrjl_dict)
- respones = res.json()
- return jsonify(respones)
- @app.route('/heartbeat',methods=['GET','POST'])
- def heartbeat():
- lrjl_verification_by = request.form.to_dict()
- if lrjl_verification_by['kami'] in Total_dict:
- vip_time = Total_dict[lrjl_verification_by['kami']]['vip']
- if int(vip_time) > int(time.time()):
- return jsonify({'code':200,'msg':'心跳验证'})
- else:
- return jsonify({'code':400,'msg':'心跳验证失败!'})
- if __name__ == '__main__':
- # 自行修改上方 'http://192.0.0.1 为易如意站点域名 或者服务器ip
- app.run(host='0.0.0.0',port='5000',debug=True)
复制代码
3, 自行修改.py的 http://192.0.0.1 为易如意开发文档-卡密登录-URL地址,需修改的是logoin函数和payCode函数里面的代码
4, flask_server.py可放在网站根目录: / 或者站点目录下
5.进入服务器运行窗口启动 flask_server.py 文件
6,易如意网络验证.lua 文件源码:
- RunUIState = true
- HeartbeatSecond = 3000
- Time = systemTime()
- KaMiLong = 16
- privateKey = '9a391cacc7a22bb9c93ae89619a94823' -- 服务器flask_server.py文件 私钥 MD5转码后的值
- publicKey = '2be10ab07b455b41220e11231279ca47' -- 服务器 公钥 MD5转码后的值 可自行修改
- function getFileJsonData()
- -- 获取注册后服务器保存客户端json文件数据
- local baespaht = getSdPath().."/com.lrjl.game"
- local lrjljsonpath = getSdPath().."/com.lrjl.game/verification.json"
- if fileExist(lrjljsonpath) then
- local ret = readFile(lrjljsonpath)
- return jsonLib.decode(ret)
- else
- if fileExist(baespaht) == false then
- mkdir(baespaht)
- end
-
- end
- end
- function MkFile()
- -- 创建一个json文件保存服务器返回数据
-
-
- end
- function heartbeat(jsonData)
- -- 心跳验证
- local getJsonData = getFileJsonData()
- print(getJsonData)
- local loginUrl = 'http://192.168.0.104:5000/heartbeat'
- local uuid = getJsonData['uuid']
- local vip = getJsonData['vip']
- local kami = getJsonData['kami']
- local sign = getMD5Sign(Time,privateKey,publicKey)
-
- while UnpinlessState do
-
- local respones = httpPost(loginUrl,string.format("kami=%s&t=%s&signTime=%s&sign=%s&uuid=%s&vip=%s",kami,os.time(),sign['signTime'],sign['sign'],uuid,vip))
- print(respones)
- if respones.msg == '心跳验证失败!'then
- print(respones.msg)
- toast(respones.msg,0,0,20)
- UnpinlessState = false
- end
- if respones.msg ~= '心跳验证' then
- ui.newLayout("layout100")
- ui.show("layout100")
- ui.setTitleText("layout100","卡密已到期请充值")
- sleep(1000*3600)
- exitScript()
- end
- sleep(HeartbeatSecond)
- end
-
-
- end
- function getMD5Sign(Time,privateKey,publicKey)
- -- 获取数据签名sign 转为md5值
- local sign = string.format("%s-%s-%s",Time,privateKey,publicKey)
-
- return {signTime=Time,sign=MD5(string.upper(sign))}
- end
- function OnClickPayCode()
- -- 卡密充值
- print('点击卡密充值')
- local getUIData = ui.getData()
- print(getUIData)
- local app = 10000
- local sign = getMD5Sign(Time,privateKey,publicKey)
- local kamiEditId1 = getUIData.kamiEditId1
- if string.len(kamiEditId1)>=KaMiLong then
- ui.setTextView("OnekamiEditId1",kamiEditId1)
-
- end
- local getUIData = ui.getData()
- local OnekamiEditId1 = getUIData.OnekamiEditId1
- local TwokamiEditId2 = getUIData.TwokamiEditId2
- local time = os.time()
- local payCodeUrl = 'http://192.168.0.104:5000/paycode'
- local respones = httpPost(payCodeUrl,string.format("app=%s&mainkm=%s&kami=%s&t=%s&signTime=%s&sign=%s",app,OnekamiEditId1,TwokamiEditId2,time,sign.signTime,sign.sign))
- print(respones)
- respones = jsonLib.decode(respones)
- if respones.msg == '充值成功'then
- local getJsonData = getFileJsonData()
- print(getJsonData)
- getJsonData.vip = respones.time
- print(getJsonData)
- local lrjljsonpath = getSdPath().."/com.lrjl.game/verification.json"
- io.output(lrjljsonpath)
- io.write(jsonLib.encode(getJsonData))
- io.close()
- print(respones.msg)
- toast(respones.msg,0,0,20)
- else
- print(respones.msg)
- toast(respones.msg,0,0,20)
- end
-
- end
- function OnClickUnpinless()
- -- 解绑设备按钮操作
- local getJsonData = getFileJsonData()
- print(getJsonData)
- if getJsonData ~= nil then
- uuid = getJsonData['uuid']
- end
- local getUIData = ui.getData()
- local sign = getMD5Sign(Time,privateKey,publicKey)
- local loginUrl = 'http://192.168.0.104:5000/unpinless'
- local lrjljsonpath = getSdPath().."/com.lrjl.game/verification.json"
- local respones = httpPost(loginUrl,string.format("kami=%s&t=%s&signTime=%s&sign=%s&uuid=%s",getUIData['kamiEditId1'],os.time(),sign['signTime'],sign['sign'],uuid))
- print(respones)
- respones = jsonLib.decode(respones)
- if respones.code == 200 then
- print(respones.msg)
- toast(respones.msg,0,0,20)
- if fileExist(lrjljsonpath) then
- delfile(lrjljsonpath)
- print('文件已删除!')
- ui.setTextView("kamiTextId2","卡密到期时间:")
- ui.setVisiblity("kamiTextId2",2)
- UnpinlessState = false
- end
- elseif respones.code == 500 then
- print(respones.msg)
- toast(respones.msg,0,0,20)
- end
-
- end
- function OnClickKaMiLogin()
- -- 卡密登录按钮操作
- -- flask 登录验证url
- UnpinlessState = true
- local uuid = ''
- local getJsonData = getFileJsonData()
- print(getJsonData)
- if getJsonData ~= nil then
- uuid = getJsonData['uuid']
- end
- local loginUrl = 'http://192.168.0.104:5000/login'
- -- 易如意创建应用ID
- local app = 10000
- -- 获取UI数据
- local getUIData = ui.getData()
- -- 获取sign签名
- local sign = getMD5Sign(Time,privateKey,publicKey)
-
- local respones = httpPost(loginUrl,string.format("kami=%s&t=%s&signTime=%s&sign=%s&uuid=%s&app=%s",getUIData['kamiEditId1'],os.time(),sign['signTime'],sign['sign'],uuid,app))
- print(respones)
- respones = jsonLib.decode(respones)
- print('登录验证返回数据:',respones)
-
- if respones.kami == getUIData['kamiEditId1'] and string.len(respones.vip) > 9 then
- local lrjljsonpath = getSdPath().."/com.lrjl.game/verification.json"
- io.output(lrjljsonpath)
- io.write(jsonLib.encode(respones))
- io.close()
- print('登录成功,数据保存完毕')
- toast("登录成功,启动设置页面!",0,0,20)
- sleep(2000)
- beginThread(heartbeat)
-
- elseif respones.msg == '心跳验证'then
- print('登录成功,启动心跳验证')
- toast("登录成功",0,0,20)
- beginThread(heartbeat)
- else
- print('卡密设备信息不一致,登录失败!')
- toast("卡密设备信息不一致,登录失败!",0,0,20)
- sleep(2000)
- toast("请充值或联系管理员!",0,0,20)
- end
- getJsonData = getFileJsonData()
-
- local timeView = os.date("%Y-%m-%d %H:%M:%S",getJsonData.vip)
- ui.setTextView("kamiTextId2",string.format("卡密到期时间:%s",timeView))
- ui.setVisiblity("kamiTextId2",1)
- end
- function clearTextData()
- -- 清空输入框文字
- ui.setEditText("kamiEditId1","",500,-2)
- ui.setEditText("OnekamiEditId1","",500,-2)
- ui.setEditText("TwokamiEditId2","",500,-2)
-
- end
- function clearTextData_1()
- -- 清空输入框文字
- ui.setEditText("OnekamiEditId1","",500,-2)
-
-
- end
- function clearTextData_2()
- -- 清空输入框文字
- ui.setEditText("TwokamiEditId2","",500,-2)
-
- end
- function RunUI()
-
- -- 启动UI界面
- ui.newLayout("layout1",-1,720)
- ui.setTitleText("layout1","易如意网络验证系统")
- ui.addTabView("layout1","tabviewId1")
- ui.addTab ("tabviewId1", "lab1", "卡密登录")
- ui.addTab ("tabviewId1", "lab2", "卡密充值")
- ui.addTextView("lab1","kamiTextId1","卡密:")
- ui.addEditText("lab1","kamiEditId1","请输入卡密",500,-2)
-
- ui.addButton("lab1","kamiLoginbtnnId1","登录")
- ui.setOnClick("kamiLoginbtnnId1","OnClickKaMiLogin()")
- ui.setOnClick("kamiEditId1","clearTextData()")
-
- ui.newRow("lab1","row1")
- ui.addButton("lab1","UnpinlessbtnnId1","解绑设备")
- ui.setOnClick("UnpinlessbtnnId1","OnClickUnpinless()")
- ui.addTextView("layout1","kamiTextId2","卡密到期时间:")
- ui.setVisiblity("kamiTextId2",2)
-
- ui.addTextView("lab2","OnekamiTextId1","主卡密")
- ui.addEditText("lab2","OnekamiEditId1","请输入主卡密",500,-2)
- ui.newRow("lab2","row2")
- ui.addTextView("lab2","OnekamiTextId2","新卡密")
- ui.addEditText("lab2","TwokamiEditId2","请输入新卡密",500,-2)
-
- ui.addButton("lab2","PayCodebtnnId1","点击充值")
- ui.setOnClick("PayCodebtnnId1","OnClickPayCode()")
- ui.setOnClick("OnekamiEditId1","clearTextData_1()")
- ui.setOnClick("TwokamiEditId2","clearTextData_2()")
-
-
- ui.show("layout1")
- while RunUIState do
- sleep(1000)
- end
-
- end
- -- 以上源码是动态UI封装代码,根据需要自行修改.
- -- 以上 http://192.168.0.104:5000 该域名端口修改为自己服务器的ip:端口
复制代码
6.1, 修改易如意网络验证.lua文件访问的url地址 http://192.168.0.104:5000改为自己服务器的即可
7,在易如意后台创建卡密-添加卡密
7.1, 设置生成卡密对应信息
运行结果:
|