# 接口客户端使用示例(Python):



'''
猫酷开放平台接入示例 (Python3.X)
'''
import hashlib
import json
from datetime import datetime

'''
pip install requests
'''
import requests


class OpenPlatformDemo(object):
    
    def __init__(self):

        '''
        开发者应用账号,由猫酷提供
        '''
        self.appID = ''  # AppID
        self.publicKey = ''  # 公钥
        self.privateKey = ''  # 私钥

    def mallcoo_post(self, url, json_data):

        '''
        :param url: 请求url
        :param post_data: 请求参数(json格式)
        :return: Response object
        '''

        timestamp = datetime.now().strftime('%Y%m%d%H%M%S')  # 时间戳

        encryptString = "{publicKey:" + self.publicKey + ",timeStamp:" + timestamp + ",data:" + json.dumps(
            json_data) + ",privateKey:" + self.privateKey + "}"  # 待加密字符串

        sign = hashlib.md5(encryptString.encode(encoding='utf-8')).hexdigest()[8:24].upper()  # 16位MD5加密(大写)

        headers = {
            'Content-Type': 'application/json;charset=utf-8',
            'AppID': self.appID,
            'PublicKey': self.publicKey,
            'TimeStamp': timestamp,
            'Sign': sign
        }

        response = requests.post(url, json=json_data, headers=headers)

        return response


if __name__ == '__main__':
    
    '''
        获取商户详情
        :return:
    '''
    def get_shop_detail():
        
        url = 'https://openapi10.mallcoo.cn/Shop/V1/GetDetail/'
        json_data = {
            'McShopID': 1000035,
            'CrmShopID': '',
            'DevShopID': ''
        }

        demo = OpenPlatformDemo()
        response = demo.mallcoo_post(url, json_data)
        print(response.status_code, response.text, sep='\n')


    get_shop_detail()





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Last Updated: 2021/3/31 上午11:15:32