分类
未分类

BOT使用教程

首先这个先分类型:当前有:

群管

娱乐

查询

杂项

分类
未分类

密码保护:233331

此内容受密码保护。如需查阅,请在下列字段中输入您的密码。

分类
未分类

自建短链后端源码

本程序是Python+Flask+Nginx搞出来的,下面就分享下代码

写的不太好,请各位大佬多多指导

# -*- coding: utf-8 -*-
from flask import render_template,request,Flask,redirect,Response
import json5
import time
import os
import hashlib,base64
from tornado.httpserver import HTTPServer
from tornado.wsgi import WSGIContainer
from tornado.ioloop import IOLoop
app=Flask(__name__)
mdict = {
        'jpeg': 'image/jpeg',
        'jpg': 'image/jpeg',
        'png': 'image/png',
        'gif': 'image/gif',
        'bmp':'image/bmp',
        'wbmp':'image/vnd.wap.wbmp'
    }
@app.errorhandler(500)
def bd(a):
    return """{"code":500,"msg":"服务器内部错误"}""" ,500
@app.errorhandler(404)
def bd1(a):
    return """{"code":404,"msg":"不存在"}""",404
@app.errorhandler(405)
def bd2(a):
    return """{"code":405,"msg":"方法不被允许"}""",405
def gettime():
    time_tuple = time.localtime()
    return ("{}-{}-{}".format(time_tuple[0],time_tuple[1],time_tuple[2],time_tuple[3]))
def cjwjj():
    timea=gettime()
    if os.path.exists('./dl/'+timea):
        pass
    else:
        os.makedirs(('./dl/'+timea))
def pdwjlx(path):
    with open(path,'r',encoding='utf-8') as f:
        data=f.read()
    data1=data.split(";")
    if data1[0]=='url':
        return ('url',data1[1])
    elif data1[0]=='html':
        return ('html',data1[1])
    elif data1[0]=='png' or data1[0]=='bmp' or data1[0]=='gif' or data1[0]=='jpg' or data1[0]=='jpge' or data1[0]=='wbmp':
        return (data1[0],data1[1])
    else:
        return (None,None)
@app.route('/cj', methods = ["POST"])
def cj():
    data = request.get_data().decode('utf-8')
    data=data.split(';')
    if len(data)==2:
        if data[0]=='url':
            url=data[1]
            m = hashlib.md5()
            m.update(url.encode('utf-8'))
            data1=(m.hexdigest())[0:6:]
            cjwjj()
            with open('./dl/'+gettime()+'/'+data1,'w',encoding='utf-8') as f:
                f.write("url;"+url)
            return json5.dumps({"code":200,"data":"https://xsl.pub/"+data1}),200
        elif data[0]=='html':
            url=data[1]
            m = hashlib.md5()
            m.update(url.encode('utf-8'))
            data1=(m.hexdigest())[0:6:]
            cjwjj()
            with open('./dl/'+gettime()+'/'+data1,'w',encoding='utf-8') as f:
                f.write("html;"+url)
            return json5.dumps({"code":200,"data":"https://xsl.pub/"+data1}),200
        elif data[0]=='png':
            data2=base64.b64decode(data[1])
            m = hashlib.md5()
            m.update(data2)
            data1=(m.hexdigest())[0:6:]
            cjwjj()
            with open('./dl/'+gettime()+'/'+data1,'w',encoding='utf-8') as f:
                f.write("png;"+data[1])
            return json5.dumps({"code":200,"data":"https://xsl.pub/"+data1}),200
        elif data[0]=='gif':
            data2=base64.b64decode(data[1])
            m = hashlib.md5()
            m.update(data2)
            data1=(m.hexdigest())[0:6:]
            cjwjj()
            with open('./dl/'+gettime()+'/'+data1,'w',encoding='utf-8') as f:
                f.write("gif;"+data[1])
            return json5.dumps({"code":200,"data":"https://xsl.pub/"+data1}),200
        elif data[0]=='jpg':
            data2=base64.b64decode(data[1])
            m = hashlib.md5()
            m.update(data2)
            data1=(m.hexdigest())[0:6:]
            cjwjj()
            with open('./dl/'+gettime()+'/'+data1,'w',encoding='utf-8') as f:
                f.write("jpg;"+data[1])
            return json5.dumps({"code":200,"data":"https://xsl.pub/"+data1}),200
        elif data[0]=='jpeg':
            data2=base64.b64decode(data[1])
            m = hashlib.md5()
            m.update(data2)
            data1=(m.hexdigest())[0:6:]
            cjwjj()
            with open('./dl/'+gettime()+'/'+data1,'w',encoding='utf-8') as f:
                f.write("jpeg;"+data[1])
            return json5.dumps({"code":200,"data":"https://xsl.pub/"+data1}),200
        elif data[0]=='bmp':
            data2=base64.b64decode(data[1])
            m = hashlib.md5()
            m.update(data2)
            data1=(m.hexdigest())[0:6:]
            cjwjj()
            with open('./dl/'+gettime()+'/'+data1,'w',encoding='utf-8') as f:
                f.write("bmp;"+data[1])
        elif data[0]=='wbmp':
            data2=base64.b64decode(data[1])
            m = hashlib.md5()
            m.update(data2)
            data1=(m.hexdigest())[0:6:]
            cjwjj()
            with open('./dl/'+gettime()+'/'+data1,'w',encoding='utf-8') as f:
                f.write("wbmp;"+data[1])
            return json5.dumps({"code":200,"data":"https://xsl.pub/"+data1}),200
        else:
            return """{"code":416,"msg":"客户端请求的范围无效"}""",416,0
    else:
        return """{"code":416,"msg":"客户端请求的范围无效"}""",416,0
@app.route('/cj/', methods = ["GET"])
def cj1():
    return """{"code":416,"msg":"客户端请求的范围无效"}""",416,0
@app.route('/cj', methods = ["GET"])
def cj2():
    return """{"code":416,"msg":"客户端请求的范围无效"}""",416,0
@app.route('/<url>/')
def tz(url):
    data2=os.listdir('dl')
    data0=(None,None)
    for i in data2:
       # print(i)
        if os.path.exists('./dl/'+i+'/'+url):
            data0=pdwjlx('./dl/'+i+'/'+url)
           # print('./dl/'+i+'/'+url)       
            break
   # print(data0)
    if data0[0]!=None:
        if data0[0]=='url':
            url2=data0[1]
            return redirect(url2)
        elif data0[0]=='html':
            url2=data0[1]
            return url2
        else:
            mode=data0[0]
            data2=data0[1]
            data3=base64.b64decode(data2)
            return Response(data3, mimetype=mdict[mode])
    return """{'code':404,'msg':'不存在'}""" ,404

@app.route('/')
def index():
    return redirect('https://blog.dllxsw.cc/?p=17')
s = HTTPServer(WSGIContainer(app))
s.listen(8080) 
IOLoop.current().start()
"""然后在nginx里配置反向代理即可"""

分类
代码

自建短链(xsl.pub)的使用教程

先说一下 这个站点其实不止短链功能,也有图床功能

下面来说一下如何使用

就是发post请求到https://xsl.pub/cj

请求数据是

短链 :

url;你要跳转的网站(带http|s)
分类
未分类

世界,您好!

欢迎使用WordPress。这是您的第一篇文章。编辑或删除它,然后开始写作吧!