python 小练习-序列号有效期验证
问题描述:
在一个网站验证该序列号是否有效
思路:
1、首先确定需求,这里需要提供一个接口来验证序列号可用。(因为以后可能涉及到程序内盗用所以留了函数调用口)
2、先找到网站请求地址,和传参字段,和返回值
3、分析返回值找到需要的字段
4、用requests方法对网址发送请求,分析返回值加以提取
#
#验证序列号有效期 :可程序内调用/ 接口调用GET传参
#参数:number(序列号),url(查询地址变动可选)
#返回值:number:当前序列号;status:序列号状态;late_end_date:最后到期日期
#
# def pah3c(request,number='',url='https://i.cnblogs.com/posts/edit'):
# result = {}
# if request.GET.get("number"):
# result['number'] = request.GET.get("number")
# elif number != '':
# result['number'] = number
# else:
# result['status'] = '请传入序列号'
# return JsonResponse(result,json_dumps_params={'ensure_ascii':False})
# # return render(request,"polls/pah3c.html",{"status":status})
# data = {
# 'serialNumber': result['number'],
# }
# x = requests.post(url, data)
# y = x.json()
# # # 检查响应状态
# if y['code'] != 200:
# result['status'] = '序列号错误'
# return JsonResponse(result,json_dumps_params={'ensure_ascii':False})
# # return render(request, "polls/pah3c.html", {"number": number,"status": status})
#
# result['last_end_date'] = y['data']['es'][0]['combinedUnitEntitlement']['oos']['lastEndDate']
# time_str = time.mktime(time.strptime(result['last_end_date'], '%Y-%m-%d'))
# #
# if time_str > time.time():
# result['status'] = '有效'
# else:
# result['status'] = '无效'
# return JsonResponse(result,json_dumps_params={'ensure_ascii':False})
# # return render(request,"polls/pah3c.html",{"number":number,"last_end_date":last_end_date,"status":status})