SMS verification code, identity verification name, and mobile phone three-element real name in three steps, teach you how to call the API interface, examples can be used

SMS verification code, identity verification name, and mobile phone three-element real-name three-step process

It is full of dry goods to share, and the code can be run after obtaining the corresponding AppKey; python3 environment
As we all know, the biggest problems faced by information systems and website business are illegal system login, login password colliding with database, data leakage, and unauthentic user information. Of course, there are many ways to improve the integrity of the system. Here are some ways to achieve immediate results
Obtain SMS Verification Code AppKey
Get identity verification name authentication AppKey
Obtain the AppKey for real-name authentication of mobile phones with three networks

1. SMS verification code

Applicable to all kinds of websites, APP and other SMS verification codes, notification SMS, etc.
Whether it is registration, login, sensitive data viewing, or adding SMS verification code verification during sensitive operations, it can effectively improve system security
Here’s how to access SMS verification code

1. Access & amp;interaction process

  1. First, you need to apply for the interface and obtain the verification code interface AppKey
  2. Create an SMS verification code template and get the template Id
  3. The client calls the verification code sending interface
  4. The server sends and stores the verification code to the database
  5. The client submits the verification code for verification

2. Interface request example

After the user obtains the AppKey, further testing can be performed: Obtain the verification code interface AppKey

Don’t talk nonsense, go directly to the sample code (pythos3, more development language examples, see here): (The premise is to get the AppKey and template ID)

python version

import random
import requests
import json

appKey='SMS verification code interface AppKey'
tplId='verification code SMS template'

class ApiRequest(object):

    def __init__(self, appKey, tplId):
        self.appKey = appKey
        self.tplId = tplId

    def sendSms(self, mobile):
        code = random.randint(100000,999999)
        """
            After the verification code is generated, it is first stored in the local database
        """


        # Call the interface to send the verification code
        resp = self. sendSmsApi(mobile, code)

        """
            Here, do some business processing according to the sending status of the verification code
        """
        return resp

    # Verification code sending interface
    def sendSmsApi(self, mobile, code):
        params={<!-- -->'key':'key','fid':0}
        headers ={<!-- -->"Content-Type": "application/x-www-form-urlencoded"}
        params = {<!-- -->
            "mobile": mobile,
            "tpl_id": self.tplId,
            "tpl_value": "#code#={}".format(code),
            "key": self.appKey,
        }
        print(params)
        resp = requests.post("http://v.juhe.cn/sms/send",params,headers=headers)
        resp_json = json. loads(resp. text)
        print(resp_json)
        ## {'reason': 'operation succeeded', 'result': {'sid': '594832C6A33A5CC7', 'fee': 1, 'count': 1 }, 'error_code': 0}
        return resp_json

mobile = '18913556768'

pet = ApiRequest(appKey,tplId)
rest = pet. sendSms(mobile)
print(rest)


Interface return example:

/****failure example**/
{<!-- -->
    "reason": "Wrong SMS template ID, please confirm through the background!!!",
    "result": [],
    "error_code": 205402
}

/**** SUCCESSFUL EXAMPLE**/
{<!-- -->
    "reason": "SMS sent successfully",
    "result": {<!-- -->
        "count": 1, /*Send count*/
        "fee": 1, /*deduction number*/
        "sid": "23d6bc4913614919a823271d820662af" /*SMS ID*/
    },
    "error_code": 0 /*sent successfully*/
}

2. User Security

Whether the user information is authentic and valid, and whether the user’s illegal use of platform information or publishing illegal speeches and other illegal acts can be traced back to the user himself
Strengthen user security management = “identity real name
There are currently two types of simple identity real names:

  • 1. Identity verification and name authentication: verify whether the name and identity number are true and valid
  • 2. Three-network mobile phone real-name authentication: According to the information of the mobile phone number, verify whether the ID number and name match

The difference between the two: Three-network mobile phone real-name authentication is safer and more reliable than identity verification.

Here is sample code python for both ways:

1. Identity verification and name authentication

Verify whether the information is consistent by passing the name + ID number
Applicable to scenarios that require user real-name authentication, such as e-commerce, games, live streaming, and finance
Apply for Identity VerificationName AuthenticationAppKey

import random
import requests
import json

appKey=''

class ApiRequest(object):

    def __init__(self, appKey):
        self.appKey = appKey

    # Authentication name
    def verify(self, idcard, name):
        params={<!-- -->'key':'key','fid':0}
        headers ={<!-- -->"Content-Type": "application/x-www-form-urlencoded"}
        params = {<!-- -->
            "idcard": mobile,
            "realname": name,
            "key": self.appKey,
        }
        print(params)
        resp = requests.post("http://op.juhe.cn/idcard/query",params,headers=headers)
        resp_json = json. loads(resp. text)
        print(resp_json)
        ## {'reason': 'success', 'result': {'res': 1, 'realname': 'name', 'idcard': ' Identity number'}, 'error_code': 0}
        return resp_json

mobile = 'ID card number'
name = 'name'
pet = ApiRequest(appKey)
rest = pet.verify(mobile,name)
print(rest)

Interface return example:

{<!-- -->
    "reason": "Success",
    "result": {<!-- -->
        "realname": "***", /*real name*/
        "idcard": "********************", /*ID card number*/
        "orderid":"J103202010151450419556", /*serial number*/
        "res": 1 /*1: match 2: not match*/
    },
    "error_code": 0
}

2. Mobile phone triple network real-name authentication

Check whether the information is consistent by passing the name + ID card number + mobile phone number
Applicable to scenarios that require user real-name authentication, such as e-commerce, games, live streaming, and finance
Apply for and obtain the AppKey for the real-name authentication of the three-network mobile phone

import random
import requests
import json

appKey=''

class ApiRequest(object):

    def __init__(self, appKey):
        self.appKey = appKey

    # Authentication name
    def verify(self, idcard, name, mobile):
        params={<!-- -->'key':'key','fid':0}
        headers ={<!-- -->"Content-Type": "application/x-www-form-urlencoded"}
        params = {<!-- -->
            "idcard": idcard,
            "realname": name,
            "mobile":mobile,
            "key": self.appKey,
        }
        print(params)
        resp = requests.post("http://v.juhe.cn/telecom/query",params,headers=headers)
        resp_json = json. loads(resp. text)
        print(resp_json)
        # {'reason': 'success', 'result': {'realname': 'name', 'mobile': 'mobile number', 'idcard\ ': 'ID card number', 'res': 1, 'remsg': 'Three-factor authentication consistent'}, 'error_code': 0}
        return resp_json

idcard = 'ID card number'
name = 'name'
mobile ='Mobile phone number'
pet = ApiRequest(appKey)
rest = pet.verify(idcard,name,mobile)
print(rest)

Interface return parameters:

{<!-- -->
    "reason": "Query succeeded",
    "result": {<!-- -->
        "realname": "***",
        "mobile": "************",
        "idcard": "********************",
        "res": 2, /*Match result: 1 matches, 2 does not match*/
        "resmsg": "The three-factor authentication is inconsistent,"/*Instructions, when res is 1, the three-factor authentication is consistent, and when res is 2, the three-factor authentication is inconsistent*/
        "types": "Mobile"/*Mobile phone operator, return when the input parameter type is 1*/
        "orderid":"J201712251904163782Ay", /* aggregate order number, return when the input parameter showid is 1 */
        "province":"Guangdong Province", /*Province of attribution*/
        "city" : "Huizhou City", /**The City of Attribution*/
        "rescode":"24", /* When the input detail is 1, return the matching detail code (when inputting 1 in the simplified version, it will always return 24),
            11: match, 21: name does not match, 22: ID does not match,
            23: The name and ID card do not match, 24: No match, the specific elements do not match unknown*/
    },
    "error_code": 0
}