Developer Interface¶
Main Interface¶
-
class
wego.api.
WeChatUser
(wego, data)[source]¶ A lazy and smart wechat user object. You can set user remark, group, groupid direct, because of group name can be repeated, so if you set the group by group name, it may not be accurate.
-
class
wego.api.
WegoApi
(settings)[source]¶ Wego api dead simple for humans.
-
analysis_push
(request)[source]¶ Analysis xml to dict and set wego push type. Wego defind WeChatPush type (which can reply has checked):
– pay –
all ✓
—msg –
text ✓
image ✓
voice ✓
video ✓
shortvideo ✓
location ✓
link ✓
—event –
subscribe ✓’
unsubscribe
scancode_push
scancode_waitmsg ✓
scan
scan_subscribe
user_location ✓
click ✓
view
Parameters: raw_xml – Raw xml. Returns: WeChatPush
object.Return type: WeChatPush.
-
change_group_name
(group, name)[source]¶ Change group name.
Parameters: - group – Group id or group name.
- name – New group name
Returns: :Bool
-
change_user_group
(openid, group)[source]¶ Change user group.
Parameters: group – Group id or group name. Returns: :Bool .
Check whether personalized menu match is correct.
:param data:user_id :return: :dict
-
close_order
(out_trade_no)[source]¶ # TODO return bool? Close order, get wechat config at https://api.mch.weixin.qq.com/pay/closeorder
Parameters: out_trade_no – Merchant order number within the system Returns: {…}
-
create_group
(name)[source]¶ Create a new group.
Parameters: name – Group name. Returns: dict: {‘id’: ‘int’, ‘name’:’str’}
Create menu by wego.button
Returns: :Bool
-
download_bill
(**kwargs)[source]¶ get wechat config at https://api.mch.weixin.qq.com/pay/downloadbill
Parameters: - bill_date –
- bill_type –
Returns: dict {…}
-
get_article_summary
(begin_date, end_date)[source]¶ Get article summary
:param date:begin_date, end_date :return: :dict
-
get_article_total
(begin_date, end_date)[source]¶ Get article total
Parameters: data – begin_date, end_date Returns: :dict
-
get_ext_userinfo
(openid)[source]¶ Get user extra info, such as subscribe, language, remark and groupid.
Returns: dict: User data
-
get_groups
()[source]¶ Get all groups.
Returns: dict: {‘your_group_id’: {‘name’:’str’, ‘count’:’int’}}
-
get_openid
(helper, code)[source]¶ Get user openid.
Parameters: code – A code that user redirect back will bring. Returns: openid
-
get_user_cumulate
(begin_date, end_date)[source]¶ GET accumulation of user
:param date:begin_date, end_date :return: :dict
-
get_user_groups
(openid)[source]¶ Get user groups.
Returns: dict: {‘your_group_id’: {‘name’:’str’, ‘count’:’int’}}
-
get_user_read
(begin_date, end_date)[source]¶ Get user read
:param data:begin_date, end_date :return : :dict
-
get_user_read_hour
(begin_date, end_date)[source]¶ Get user read hour
param data:begin_date, end_date return : :dict
Get user share
param data:begin_data,end_date return : :dict
Get user share
param data:begin_date, end_date retur : :dict
-
get_userinfo
(helper, openid)[source]¶ Get user info.
Returns: WeChatUser
object
-
get_variation_number_of_user
(begin_date, end_date)[source]¶ Get Variation on number of user
:param data:begin_date, end_date :return: :dict
-
login_required
(func)[source]¶ Decorator:use for request function, and it will init an independent WegoApi instance.
-
pay_report
(**kwargs)[source]¶ get wechat config at https://api.mch.weixin.qq.com/payitil/report
Parameters: - interface_url –
- execute_time –
- return_code –
- result_code –
- user_ip –
Returns: dict{…}
-
query_order
(out_trade_no=None, transaction_id=None)[source]¶ # TODO https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2 Order query setting, get wechat config at https://api.mch.weixin.qq.com/pay/orderquery Choose one in out_trade_no and transaction_id as parameter pass to this function
Parameters: | transaction_id (out_trade_no) – WeChat order number, priority in use. Merchants system internal order number, when didn’t provide transaction_id need to pass this. Returns: {…}
-
query_refund
(**kwargs)[source]¶ get wechat config at https://api.mch.weixin.qq.com/pay/refundquery
Parameters: | out_trade_no | out_refund_no | refund_id (transaction_id) – One out of four Returns: dict {…}
-
redirect_for_code
(helper)[source]¶ Let user jump to wechat authorization page.
Returns: Redirect object
-
refund_order
(**kwargs)[source]¶ Merchant order number within the system, get wechat config at https://api.mch.weixin.qq.com/secapi/pay/refund
Following parameters are necessary, you must be included in the kwargs and you must follow the format below as the parameters’s key
Parameters: - or transaction_id (out_trade_no) – WeChat order number, priority in use. Merchants system internal order number, when didn’t provide transaction_id need to pass this.
- out_refund_no – Merchants system within the refund number, merchants within the system, only the same refund order request only a back many times
- total_fee – Total amount of orders, the unit for points, only as an integer, see the payment amount
- refund_fee – Refund the total amount, total amount of the order, the unit for points, only as an integer, see the payment amount
- op_user_id – Operator account, the default for the merchants
Returns: {…}
-
unified_order
(**kwargs)[source]¶ # TODO Unifiedorder settings, get wechat config at https://api.mch.weixin.qq.com/pay/unifiedorder You can take return value as wechat api onBridgeReady’s parameters directly
You don’t need to include appid, mch_id, nonce_str and sign because these three parameters set by WeChatApi, but the following parameters are necessary, you must be included in the kwargs and you must follow the format below as the parameters’s key
Parameters: - openid – User openid.
- body – Goods are simply described, the field must be in strict accordance with the specification, specific see parameters
- out_trade_no – Merchants system internal order number, within 32 characters, can include letters, other see merchant order number
- total_fee – Total amount of orders, the unit for points, as shown in the payment amount
- spbill_create_ip – APP and web payment submitted to client IP, Native fill call WeChat payment API machine IP.
- notify_url – (optional) Default is what you set at init. Receive pay WeChat asynchronous notification callback address, notify the url must be accessible url directly, cannot carry parameters.
- trade_type – Values are as follows: the JSAPI, NATIVE APP, details see parameter regulation
Returns: {‘appId’: string, ‘timeStamp’: value, ‘nonceStr’: value, ‘package’: value, ‘signType’: value, ‘paySign’: value,}
-
Wechat Interface¶
-
class
wego.wechat.
WeChatApi
(settings)[source]¶ WeChat Api just do one thing: give params to wechat and get the data what wechat return.
-
change_group_name
(groupid, name)[source]¶ Change group name.
Parameters: - groupid – Group ID.
- name – New name.
Returns: Raw data that wechat returns.
-
change_user_group
(openid, groupid)[source]¶ Move user to a new group.
Parameters: - openid – User openid.
- groupid – Group ID.
Returns: Raw data that wechat returns.
Check whether personalized menu match is correct.
:param data:user_id :return:Raw data that wechat returns.
Create a conditional menu.
Parameters: data – Menu data. Returns: Raw data that wechat returns.
-
create_group
(name)[source]¶ Create a user group.
Parameters: name – Group name. Returns: Raw data that wechat returns.
Create a menu.
Parameters: data – Menu data. Returns: Raw data that wechat returns.
Delete all menus, contain conditional menu.
::return: Raw data that wechat returns.
Delete conditional menus, contain conditional menu.
Returns: Raw data that wechat returns.
-
del_group
(groupid)[source]¶ Delete a group.
Parameters: groupid – Group id. Returns: Raw data that wechat returns.
-
get_access_token
(code)[source]¶ Use code for get access token, refresh token, openid etc.
Parameters: code – A code see function get_code_url. Returns: Raw data that wechat returns.
-
get_article_summary
(begin_date, end_date)[source]¶ Get article summary
:param data:begin_date, end_date :return :Raw data that wechat returns.
-
get_article_total
(begin_date, end_date)[source]¶ Get article total
:param data:begin_date, end_date :return :Raw data that wechat returns.
-
get_code_url
(redirect_url, state)[source]¶ Get the url which 302 jump back and bring a code.
Parameters: - redirect_url – Jump back url
- state – Jump back state
Returns: url
Get all menus.
Returns: Raw data that wechat returns.
-
get_user_cumulate
(begin_date, end_date)[source]¶ GET accumulation of user
:param date:begin_date, end_date :return:Raw data that wechat returns.
-
get_user_read
(begin_date, end_date)[source]¶ Get user read
:param data:begin_date, end_date :return :Raw data that wechat returns.
-
get_user_read_hour
(begin_date, end_date)[source]¶ Get user read hour
param data:begin_date, end_date return :Raw data that wechat return.
Get user share
param data:begin_data,end_date return :Raw data that wechat return.
Get user share
param data:begin_date, end_date retur :Raw data that wechat return.
-
get_userinfo
(openid)[source]¶ Get user info with global access token (content subscribe, language, remark and groupid).
Parameters: openid – User openid. Returns: Raw data that wechat returns.
-
get_userinfo_by_token
(openid, access_token)[source]¶ Get user info with user access token (without subscribe, language, remark and groupid).
Parameters: - openid – User openid.
- access_token – function get_access_token returns.
Returns: Raw data that wechat returns.
-
get_variation_number_of_user
(begin_date, end_date)[source]¶ Get variation in number od user
:param data:begin_date, end_date :return:Raw data that wechat returns.
-
get_wechat_servers_list
()[source]¶ Get wechat servers list
Parameters: data – Returns: Raw data that wechat returns.
-
is_access_token_has_expired
(sele, openid, access_token)[source]¶ Determine whether the user access token has expired
Parameters: - openid – User openid.
- access_token – function get_access_token returns.
Returns: Raw data that wechat returns.
-
Settings Interface¶
wego.settings
default setting
-
wego.settings.
check_settings
(settings)[source]¶ check if settings is available
Parameters: settings – a dict. Returns: None
-
wego.settings.
init
(**kwargs)[source]¶ Init settings, get wechat config at https://mp.weixin.qq.com
Parameters: - APP_ID – Wechat AppID get it at basic configuration(基本配置).
- APP_SECRET – Wechat AppSecret get it at basic configuration(基本配置).
- REGISTER_URL – As same as you set at interface permissions(接口权限) >> authorized users obtain basic information page(网页授权获取用户基本信息).
- HELPER – Official helper ‘wego.helpers.DjangoHelper’ and ‘wego.helpers.TornadoHelper’ or you can customized yourself helper with http://wego.quseit.com/customized/helper(building).
- MCH_ID – (optional) Mac ID get it at https://pay.weixin.qq.com/ (商户号).
- MCH_SECRET – (optional) MCH SECRET As same as you set at https://pay.weixin.qq.com/ (API 密钥).
- CERT_PEM_PATH – (optional) Path to apiclient_cert.pem.
- KEY_PEM_PATH – (optional) Path to apiclient_key.pem.
- PAY_NOTIFY_PATH – (optional) Default notify url for wechat pay callback.
- PUSH_TOKEN – (optional) Set at basic configuration(基本配置).
- PUSH_ENCODING_AES_KEY – (optional) Set at basic configuration(基本配置).
- GET_GLOBAL_ACCESS_TOKEN – (optional) A function that return a global access token, if your application run at multiple servers it required. How to customized your GET_GLOBAL_ACCESS_TOKEN: http://wego.quseit.com/customized/GET_GLOBAL_ACCESS_TOKEN(building).
- USERINFO_EXPIRE – (optional) Set number of seconds expired, default is 0. subscribe, language, remark and groupid still is real time.
- REDIRECT_PATH – (optional) Default redirect path, redirect when we get user`s authorize.
- REDIRECT_STATE – (optional) Default redirect state, redirect when we get user`s authorize.
- DEBUG – (optional) Default is True, When Debug equal True it will log all information and wechat payment only spend a penny(0.01 yuan).
Returns: WegoApi
object.Return type: WegoApi.