所以我正在研究REST API,并对aadhar卡进行KYC验证。这是我的代码:
管理员.py
def save_model(self, request, obj, form, change): customer_id = obj.customer_id customer_object = Customer.objects.get(id=customer_id) first_name = customer_object.first_name middle_name = customer_object.middle_name last_name = customer_object.last_name customer_name = first_name + " " + last_name date_of_birth = customer_object.date_of_birth aadhar_card = obj.aadhar_card # Send OTP request url = AADHAR_AUTH_URL_OTP_SEND header = { "Content-Type":"application/json", "x-karza-key" : KARZA_TOKEN } payload = { "aadhaarNo": obj.aadhar_card, "consent": "Y" } result = requests.post(url, data=json.dumps(payload), headers=header, verify=False) result_json = result.json() request_id = result_json.get('requestId', '') # Verify OTP request if request_id: otp = input("Enter OTP received on registered mobile number: ") # ask the user to input the OTP url = AADHAR_AUTH_URL_VERIFIED_OTP payload = { "aadhaarNo": obj.aadhar_card, "consent": "Y", "requestId": request_id, "otp": otp } result = requests.post(url, data=json.dumps(payload), headers=header, verify=False) result_json = result.json() status = result_json.get('result', {}).get('message', '') # Save the results to the database if change: obj = aadhar_card.objects.get(pk=obj.pk) obj.aadhar_card = aadhar_card obj.aadhar_request_json = json.dumps(payload) obj.aadhar_response_json = json.dumps(result_json) obj.updated_by = request.user.id status_code = result_json.get('statusCode') if status_code == 101: obj.status = 101 # Verified else: obj.status = 3 # Not Verified obj.save() else: obj.aadhar_card = aadhar_card obj.aadhar_request_json = json.dumps(payload) obj.aadhar_response_json = json.dumps(result_json) obj.added_by = request.user.id status_code = result_json.get('statusCode') if status_code == 101: obj.status = 101 # Verified else: obj.status = 3 # Not Verified obj.save() super().save_model(request, obj, form, change)
Now the problem is that i have to enter the OTP in terminal. How can I take otp from the user on DJANGO ADMIN PANEL it self as i am not using any views i have worked on 管理员.py only.
任何帮助都将不胜感激!