閱讀951 返回首頁    go iPhone_iPad_Mac_apple


Python教程__sdk_數據風控-阿裏雲

創建Access Key

1.登陸阿裏雲賬號;2.打開“我的Access Key”頁麵,頁麵地址:https://i.aliyun.com/access_key/;3.創建Access Key。

安裝SDK

  • 開發環境阿裏雲python支持python2.7及以上版本。
  • 安裝步驟1、下載python_sdk.zip,將壓縮包解壓後放置到係統的任意目錄(需要保證有讀取權限)。

快速入門

初始化一個IClientProfile1、與阿裏雲SDK相關的類都在包com.aliyuncs.IAcsClient下;2、IClientProfile是與API交互的接口,SDK的操作都是通過IClientProfile完成的;3、IClientProfile可以複用,建議設置成應用程序全局唯一的。

  1. clt = client.AcsClient(ak=accessKeyId,secret=accessKeySecret,region_id='cn-hangzhou') #阿裏雲頒發的appkey和secret

示例代碼

  • 風險識別API

    1. def TestQuerySimpleRequest():
    2. appkey = afs_appkey #從前端傳入
    3. scene = 'xxxx' #從前端傳入
    4. token = 'xxxx' #從前端傳入
    5. accesskey = afs_accesskey #數據風控服務頒發
    6. timestamp =str(int(time.time())*1000) #時間戳
    7. tr = '{"email":"12345677@qq.com"}' #透傳參數:IP、phonenumber、email
    8. enc = afs_appkey+afs_accesskey+token+timestamp #afs_accesskey產品端頒發
    9. temp = md5.new()
    10. temp.update(enc)
    11. serno = temp.hexdigest()
    12. request = QuerySimpleRequest.QuerySimpleRequest()
    13. request.set_SceneId(scene)
    14. request.set_AppKey(appkey)
    15. request.set_TokenId(token)
    16. request.set_SerialNo(serno)
    17. request.set_Trans(tr)
    18. request.set_TimeStamp(timestamp)
    19. try:
    20. response = clt.do_action(request)
    21. print response
    22. except:
    23. print 'error'
  • 風險攔截API

    1. def TestAuthenticateRequest():
    2. appkey = afs_appkey #數據風控服務頒發
    3. accesskey = afs_accesskey #數據風控服務頒發
    4. token = 'xxxxxxx' #從前端傳入
    5. sig = 'xxxxxxxxx' #從前端傳入
    6. sessionid = 'xxxx' #從前端傳入
    7. timestamp =str(int(time.time())*1000) #時間戳
    8. remoteip = '192.168.1.1' # 傳入IP
    9. #to calculate serno
    10. enc = afs_appkey+afs_accesskey+token+sig
    11. temp = md5.new()
    12. temp.update(enc)
    13. serno = temp.hexdigest()
    14. request = AuthenticateRequest.AuthenticateRequest()
    15. request.set_AppKey(appkey)
    16. request.set_Token(token)
    17. request.set_Sig(sig)
    18. request.set_Serno(serno)
    19. request.set_SessionId(sessionid)
    20. request.set_RemoteIp(remoteip)
    21. request.set_TimeStamp(timestamp)
    22. try:
    23. response = clt.do_action(request)
    24. print response
    25. except:
    26. print 'error'

最後更新:2016-11-23 17:16:05

  上一篇:go PHP教程__sdk_數據風控-阿裏雲
  下一篇:go 2016年11月21日數據風控控製台升級__產品升級更新_數據風控-阿裏雲