|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
10 |
|
from __future__ import absolute_import, unicode_literals |
|
3
|
|
|
|
|
4
|
10 |
|
import json |
|
5
|
10 |
|
import datetime |
|
6
|
|
|
|
|
7
|
10 |
|
from optionaldict import optionaldict |
|
8
|
|
|
|
|
9
|
10 |
|
from wechatpy.client.api.base import BaseWeChatAPI |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
10 |
|
class WeChatMarketing(BaseWeChatAPI): |
|
13
|
10 |
|
API_BASE_URL = 'https://api.weixin.qq.com/marketing/' |
|
14
|
|
|
|
|
15
|
10 |
|
def add_user_action_sets(self, _type, name, description, version='v1.0'): |
|
16
|
|
|
""" |
|
17
|
|
|
创建数据源 |
|
18
|
|
|
https://wximg.qq.com/wxp/pdftool/get.html?id=rkalQXDBM&pa=39 |
|
19
|
|
|
|
|
20
|
|
|
:param _type: 用户行为源类型 |
|
21
|
|
|
:param name: 用户行为源名称 必填 |
|
22
|
|
|
:param description: 用户行为源描述,字段长度最小 1 字节,长度最大 128 字节 |
|
23
|
|
|
:param version: 版本号 v1.0 |
|
24
|
|
|
:return: 数据源唯一ID |
|
25
|
|
|
""" |
|
26
|
|
|
return self._post( |
|
27
|
|
|
'user_action_sets/add', |
|
28
|
|
|
params={'version': version}, |
|
29
|
|
|
json=optionaldict( |
|
30
|
|
|
type=_type, |
|
31
|
|
|
name=name, |
|
32
|
|
|
description=description, |
|
33
|
|
|
version=version |
|
34
|
|
|
), |
|
35
|
|
|
result_processor=lambda x: x['data']['user_action_set_id'] |
|
36
|
|
|
) |
|
37
|
|
|
|
|
38
|
10 |
|
def get_user_action_sets(self, user_action_set_id, version='v1.0'): |
|
39
|
|
|
""" |
|
40
|
|
|
获取数据源信息 |
|
41
|
|
|
|
|
42
|
|
|
:param user_action_set_id: 数据源唯一ID |
|
43
|
|
|
:param version: 版本号 v1.0 |
|
44
|
|
|
""" |
|
45
|
|
|
return self._get( |
|
46
|
|
|
'user_action_sets/get', |
|
47
|
|
|
params={'version': version, 'user_action_set_id': user_action_set_id}, |
|
48
|
|
|
result_processor=lambda x: x['data']['list'] |
|
49
|
|
|
) |
|
50
|
|
|
|
|
51
|
10 |
|
def add_user_actions(self, actions=(), version='v1.0'): |
|
52
|
|
|
""" |
|
53
|
|
|
回传数据 |
|
54
|
|
|
|
|
55
|
|
|
https://wximg.qq.com/wxp/pdftool/get.html?id=rkalQXDBM&pa=39 |
|
56
|
|
|
|
|
57
|
|
|
:param actions: 用户行为源类型 |
|
58
|
|
|
:param version: 版本号 v1.0 |
|
59
|
|
|
""" |
|
60
|
|
|
return self._post( |
|
61
|
|
|
'user_actions/add', |
|
62
|
|
|
params={'version': version}, |
|
63
|
|
|
json={'actions': actions} |
|
64
|
|
|
) |
|
65
|
|
|
|
|
66
|
10 |
|
def get_ad_leads(self, start_date=None, end_date=None, filtering=(), page=1, page_size=100, version='v1.0'): |
|
67
|
|
|
""" |
|
68
|
|
|
获取朋友圈销售线索数据接口 |
|
69
|
|
|
|
|
70
|
|
|
:param start_date: 开始日期 默认今天 |
|
71
|
|
|
:param end_date: 结束日期 默认今天 |
|
72
|
|
|
:param filtering: 过滤条件 [{field: 过滤字段, operator: 操作符, values: 字段取值}] |
|
73
|
|
|
:param page: 页码,获取指定页数据 |
|
74
|
|
|
:param page_size: 一页获取的数据条数(1-100) |
|
75
|
|
|
:param version: 版本号 v1.0 |
|
76
|
|
|
""" |
|
77
|
|
|
today = datetime.date.today() |
|
78
|
|
|
if start_date is None: |
|
79
|
|
|
start_date = today |
|
80
|
|
|
if end_date is None: |
|
81
|
|
|
end_date = today |
|
82
|
|
|
if isinstance(start_date, datetime.date): |
|
83
|
|
|
start_date = start_date.strftime("%Y-%m-%d") |
|
84
|
|
|
if isinstance(end_date, datetime.date): |
|
85
|
|
|
end_date = end_date.strftime("%Y-%m-%d") |
|
86
|
|
|
|
|
87
|
|
|
return self._get( |
|
88
|
|
|
'wechat_ad_leads/get', |
|
89
|
|
|
params=optionaldict( |
|
90
|
|
|
date_range=json.dumps({'start_date': start_date, 'end_date': end_date}), |
|
91
|
|
|
filtering=json.dumps(filtering) if filtering else None, |
|
92
|
|
|
page=page, |
|
93
|
|
|
page_size=page_size, |
|
94
|
|
|
version=version |
|
95
|
|
|
), |
|
96
|
|
|
result_processor=lambda x: x['data'] |
|
97
|
|
|
) |
|
98
|
|
|
|