44"""
55File: client.py
66Author: goodspeed
7- Email: cacique1103@gmail.com
7+ Email: hi@gusibi.mobi
88Github: https://github.com/gusibi
99Date: 2015-02-06
10+ UpdatedDate: 2019-06-10
1011Description: Weixin OAuth2
1112"""
1213
@@ -199,6 +200,25 @@ def __init__(self, *args, **kwargs):
199200 raise Exception ("Unsupported format" )
200201 super (WXAPPAPI , self ).__init__ (* args , ** kwargs )
201202
203+ send_template = bind_method (
204+ path = "/cgi-bin/message/wxopen/template/send" ,
205+ method = "POST" ,
206+ accepts_parameters = ["json_body" ],
207+ response_type = "entry" ,
208+ )
209+ send_template .__doc__ = """
210+ # 发送模板消息
211+ 参数:
212+ json_body: object
213+ json_body 结构:
214+ touser string 是 接收者(用户)的 openid
215+ template_id string 是 所需下发的模板消息的id
216+ page string 否 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
217+ form_id string 是 表单提交场景下,为 submit 事件带上的 formId;支付场景下,为本次支付的 prepay_id
218+ data Object 否 模板内容,不填则下发空模板。具体格式请参考示例。
219+ emphasis_keyword string 否 模板需要放大的关键词,不填则默认无放大
220+ """
221+
202222
203223class WxAppCloudAPI (oauth2 .OAuth2API ):
204224
@@ -352,7 +372,7 @@ def upload_file(self, json_body=None):
352372 ("x-cos-meta-fileid" , pre_resp .get ("cos_file_id" )),
353373 ("Signature" , pre_resp .get ("authorization" )),
354374 ("file" , file_data ), # file 一定要放到最后,血泪的教训
355- ]
375+ ]
356376 # encode
357377 params = [(smart_str (k ), v ) for k , v in files ]
358378 resp = requests .post (pre_resp .get ("url" ), files = params )
@@ -364,9 +384,7 @@ def upload_file(self, json_body=None):
364384 results = content_obj .get ("Error" , {})
365385 raise WeixinAPIError (status_code , results ["Code" ], results ["Message" ])
366386 else :
367- raise WeixinAPIError (
368- 400 , pre_resp ["errcode" ], pre_resp ["errmsg" ]
369- )
387+ raise WeixinAPIError (400 , pre_resp ["errcode" ], pre_resp ["errmsg" ])
370388
371389 # 获取文件下载链接
372390 batch_download_file = bind_method (
0 commit comments