|
突破支付宝同时实名3个的技术上线,纯好奇摸索出来的。importrequestsimportjson#替换为你的应用ID和应用私钥APP_ID='your_app_id'APP_PRIVATE_KEY='your_private_key'#请求支付宝实名认证接口defalipay_realname_auth(real_name,id_card):url='https://openapi.alipay.com/gateway.do'#构造请求参数params={'app_id':APP_ID,'method':'alipay.user.certify.open.certify','charset':'utf-8','sign_type':'RSA2','timestamp':datetime.datetime.now().strftime('%Y-%m-%d%H:%M:%S'),'version':'1.0','biz_content':json.dumps({'cert_name':real_name,'cert_no':id_card})}#生成签名sign=generate_sign(params)params['sign']=sign#发送请求response=requests.post(url,data=params)result=response.json()returnresult#生成签名defgenerate_sign(params):unsigned_items=sorted(params.items())unsigned_string="&".join("{}={}".format(k,v)fork,vinunsigned_items)signature=sign(unsigned_string,APP_PRIVATE_KEY,'RSA2')returnsignature#签名函数,这里使用的是RSA2算法defsign(unsigned_string,private_key,sign_type):fromCrypto.PublicKeyimportRSAfromCrypto.SignatureimportPKCS1_v1_5fromCrypto.HashimportSHA256importbase64key=RSA.importKey(private_key)signer=PKCS1_v1_5.new(key)digest=SHA256.new()digest.update(unsigned_string.encode('utf-8'))ifsign_type=='RSA':sign=signer.sign(digest)else:fromCrypto.SignatureimportPKCS1_v1_5fromCrypto.HashimportSHA256signer=PKCS1_v1_5.new(key)digest=SHA256.new()digest.update(unsigned_string.encode('utf-8'))sign=signer.sign(digest)signature=base64.b64encode(sign)returnsignature#示例调用result=alipay_realname_auth('张三','身份证号码')print(result)此为认证原理,突破之后可以解决账号不够用的问题了2024.4.24仅供参考
|
|