@@ -0,0 +1,16 @@  | 
            ||
| 1 | 
                +# -*- coding: utf-8 -*-  | 
            |
| 2 | 
                +  | 
            |
| 3 | 
                +from __future__ import division  | 
            |
| 4 | 
                +  | 
            |
| 5 | 
                +from django_logit import logit  | 
            |
| 6 | 
                +from django_response import response  | 
            |
| 7 | 
                +  | 
            |
| 8 | 
                +from utils.tencentcloud.faceid import get_eid_token  | 
            |
| 9 | 
                +  | 
            |
| 10 | 
                +  | 
            |
| 11 | 
                +@logit  | 
            |
| 12 | 
                +def get_faceid_eid_token(request):  | 
            |
| 13 | 
                + eidtoken = get_eid_token()  | 
            |
| 14 | 
                +    return response(data={
               | 
            |
| 15 | 
                + 'eidtoken': eidtoken,  | 
            |
| 16 | 
                + })  | 
            
                @@ -5,7 +5,8 @@ from django_file_upload import views as file_views  | 
            ||
| 5 | 5 | 
                 | 
            
| 6 | 6 | 
                from api import (admin_views, clerk_views, complement_views, distributor_views, encrypt_views, express_views, log_views,  | 
            
| 7 | 7 | 
                maintenance_point_views, maintenance_views, mch_views, member_views, model_views, operator_views,  | 
            
| 8 | 
                - refresh_views, sr_views, staff_views, tenancy_admin_views, tenancy_views, wx_views, wxa_views)  | 
            |
| 8 | 
                + refresh_views, sr_views, staff_views, tenancy_admin_views, tenancy_views, tencentcloud_views, wx_views,  | 
            |
| 9 | 
                + wxa_views)  | 
            |
| 9 | 10 | 
                from miniapp import qy_views  | 
            
| 10 | 11 | 
                from miniapp import views as mini_views  | 
            
| 11 | 12 | 
                from page import oauth_views, sale_views, screen_views  | 
            
                @@ -356,3 +357,8 @@ urlpatterns += [  | 
            ||
| 356 | 357 | 
                 | 
            
| 357 | 358 | 
                # 快递信息回调接口  | 
            
| 358 | 359 | 
                ]  | 
            
| 360 | 
                +  | 
            |
| 361 | 
                +# 腾讯云  | 
            |
| 362 | 
                +urlpatterns += [  | 
            |
| 363 | 
                + url(r'^tencentcloud/faceid/eidtoken$', tencentcloud_views.get_faceid_eid_token, name='tencentcloud_get_faceid_eid_token'),  | 
            |
| 364 | 
                +]  | 
            
                @@ -233,6 +233,16 @@ WECHAT = {
               | 
            ||
| 233 | 233 | 
                MEMBER_CARD_ID_TAMRON = ''  | 
            
| 234 | 234 | 
                MEMBER_CARD_ID_HANYUAN = ''  | 
            
| 235 | 235 | 
                 | 
            
| 236 | 
                +# 腾讯云  | 
            |
| 237 | 
                +TENCENTCLOUD = {
               | 
            |
| 238 | 
                +    'default': {
               | 
            |
| 239 | 
                + 'appid': '',  | 
            |
| 240 | 
                + 'secret_id': '',  | 
            |
| 241 | 
                + 'secret_key': '',  | 
            |
| 242 | 
                + 'merchant_id': '',  | 
            |
| 243 | 
                + },  | 
            |
| 244 | 
                +}  | 
            |
| 245 | 
                +  | 
            |
| 236 | 246 | 
                # 七牛设置  | 
            
| 237 | 247 | 
                 QINIU = {
               | 
            
| 238 | 248 | 
                'access_key': 'yCE3xWXduLTERkx_vSNVAIHNcg1pje6EwygiRPjP',  | 
            
                @@ -0,0 +1,51 @@  | 
            ||
| 1 | 
                +# -*- coding: utf-8 -*-  | 
            |
| 2 | 
                +  | 
            |
| 3 | 
                +import json  | 
            |
| 4 | 
                +  | 
            |
| 5 | 
                +from django.conf import settings  | 
            |
| 6 | 
                +from tencentcloud.common import credential  | 
            |
| 7 | 
                +from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException  | 
            |
| 8 | 
                +from tencentcloud.common.profile.client_profile import ClientProfile  | 
            |
| 9 | 
                +from tencentcloud.common.profile.http_profile import HttpProfile  | 
            |
| 10 | 
                +from tencentcloud.faceid.v20180301 import faceid_client, models  | 
            |
| 11 | 
                +  | 
            |
| 12 | 
                +  | 
            |
| 13 | 
                +tencentcloud_cfg = settings.TENCENTCLOUD.get('default', {})
               | 
            |
| 14 | 
                +secret_id = tencentcloud_cfg.get('secret_id')
               | 
            |
| 15 | 
                +secret_key = tencentcloud_cfg.get('secret_key')
               | 
            |
| 16 | 
                +merchant_id = tencentcloud_cfg.get('merchant_id')
               | 
            |
| 17 | 
                +  | 
            |
| 18 | 
                +  | 
            |
| 19 | 
                +def get_eid_token():  | 
            |
| 20 | 
                + try:  | 
            |
| 21 | 
                + # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密  | 
            |
| 22 | 
                + # 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取  | 
            |
| 23 | 
                + cred = credential.Credential(secret_id, secret_key)  | 
            |
| 24 | 
                + # 实例化一个http选项,可选的,没有特殊需求可以跳过  | 
            |
| 25 | 
                + httpProfile = HttpProfile()  | 
            |
| 26 | 
                + httpProfile.endpoint = "faceid.tencentcloudapi.com"  | 
            |
| 27 | 
                +  | 
            |
| 28 | 
                + # 实例化一个client选项,可选的,没有特殊需求可以跳过  | 
            |
| 29 | 
                + clientProfile = ClientProfile()  | 
            |
| 30 | 
                + clientProfile.httpProfile = httpProfile  | 
            |
| 31 | 
                + # 实例化要请求产品的client对象,clientProfile是可选的  | 
            |
| 32 | 
                + client = faceid_client.FaceidClient(cred, "", clientProfile)  | 
            |
| 33 | 
                +  | 
            |
| 34 | 
                + # 实例化一个请求对象,每个接口都会对应一个request对象  | 
            |
| 35 | 
                + req = models.GetEidTokenRequest()  | 
            |
| 36 | 
                +        params = {
               | 
            |
| 37 | 
                + "MerchantId": merchant_id  | 
            |
| 38 | 
                + }  | 
            |
| 39 | 
                + req.from_json_string(json.dumps(params))  | 
            |
| 40 | 
                +  | 
            |
| 41 | 
                + # 返回的resp是一个GetEidTokenResponse的实例,与请求对象对应  | 
            |
| 42 | 
                + resp = client.GetEidToken(req)  | 
            |
| 43 | 
                + # 输出json格式的字符串回包  | 
            |
| 44 | 
                + # print(resp.to_json_string())  | 
            |
| 45 | 
                +  | 
            |
| 46 | 
                + return resp.EidToken  | 
            |
| 47 | 
                +  | 
            |
| 48 | 
                + except TencentCloudSDKException as err:  | 
            |
| 49 | 
                + # print(err)  | 
            |
| 50 | 
                +  | 
            |
| 51 | 
                + return ''  |