Developer Interface

Main Interface

class wego.api.WeChatPush(data, crypto=None, nonce=None)[源代码]
class wego.api.WeChatUser(wego, data)[源代码]

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.

get_ext_userinfo()[源代码]

Get user extra info, such as subscribe, language, remark and groupid.

返回:
dict:User data
class wego.api.WegoApi(settings)[源代码]

Wego api dead simple for humans.

analysis_push(request)[源代码]

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

参数:raw_xml – Raw xml.
返回:WeChatPush object.
返回类型:WeChatPush.
change_group_name(group, name)[源代码]

Change group name.

参数:
  • group – Group id or group name.
  • name – New group name
返回:

:Bool

change_user_group(openid, group)[源代码]

Change user group.

参数:group – Group id or group name.
返回::Bool .
check_personalized_menu_match(user_id)[源代码]

Check whether personalized menu match is correct.

:param data:user_id :return: :dict

close_order(out_trade_no)[源代码]

# TODO return bool? Close order, get wechat config at https://api.mch.weixin.qq.com/pay/closeorder

参数:out_trade_no – Merchant order number within the system
返回:{...}
create_group(name)[源代码]

Create a new group.

参数:name – Group name.
返回:
dict:{‘id’: ‘int’, ‘name’:’str’}
create_menu(*args, **kwargs)[源代码]

Create menu by wego.button

返回::Bool
del_group(group)[源代码]

Delete group.

参数:group – Group id or group name.
返回::Bool
download_bill(**kwargs)[源代码]

get wechat config at https://api.mch.weixin.qq.com/pay/downloadbill

参数:
  • bill_date
  • bill_type
返回:

dict {...}

get_article_summary(begin_date, end_date)[源代码]

Get article summary

:param date:begin_date, end_date :return: :dict

get_article_total(begin_date, end_date)[源代码]

Get article total

参数:data – begin_date, end_date
返回::dict
get_ext_userinfo(openid)[源代码]

Get user extra info, such as subscribe, language, remark and groupid.

返回:
dict:User data
get_groups()[源代码]

Get all groups.

返回:
dict:{‘your_group_id’: {‘name’:’str’, ‘count’:’int’}}
get_openid(helper, code)[源代码]

Get user openid.

参数:code – A code that user redirect back will bring.
返回:openid
get_user_cumulate(begin_date, end_date)[源代码]

GET accumulation of user

:param date:begin_date, end_date :return: :dict

get_user_groups(openid)[源代码]

Get user groups.

返回:
dict:{‘your_group_id’: {‘name’:’str’, ‘count’:’int’}}
get_user_read(begin_date, end_date)[源代码]

Get user read

:param data:begin_date, end_date :return : :dict

get_user_read_hour(begin_date, end_date)[源代码]

Get user read hour

param data:begin_date, end_date return : :dict

get_user_share(begin_date, end_date)[源代码]

Get user share

param data:begin_data,end_date return : :dict

get_user_share_hour(begin_date, end_date)[源代码]

Get user share

param data:begin_date, end_date retur : :dict

get_userinfo(helper, openid)[源代码]

Get user info.

返回:WeChatUser object
get_variation_number_of_user(begin_date, end_date)[源代码]

Get Variation on number of user

:param data:begin_date, end_date :return: :dict

get_wechat_servers_list()[源代码]

Get wechat servers list

返回::list
login_required(func)[源代码]

Decorator:use for request function, and it will init an independent WegoApi instance.

make_sign(data)[源代码]

Generate wechat pay for signature

pay_report(**kwargs)[源代码]

get wechat config at https://api.mch.weixin.qq.com/payitil/report

参数:
  • interface_url
  • execute_time
  • return_code
  • result_code
  • user_ip
返回:

dict{...}

query_order(out_trade_no=None, transaction_id=None)[源代码]

# 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

参数:| 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.
返回:{...}
query_refund(**kwargs)[源代码]

get wechat config at https://api.mch.weixin.qq.com/pay/refundquery

参数:| out_trade_no | out_refund_no | refund_id (transaction_id) – One out of four
返回:dict {...}
redirect_for_code(helper)[源代码]

Let user jump to wechat authorization page.

返回:Redirect object
refund_order(**kwargs)[源代码]

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

参数:
  • 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
返回:

{...}

unified_order(**kwargs)[源代码]

# 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

参数:
  • 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
返回:

{‘appId’: string, ‘timeStamp’: value, ‘nonceStr’: value, ‘package’: value, ‘signType’: value, ‘paySign’: value,}

verification_token(openid, access_token)[源代码]

Determine whether the user access token has expired

参数:
  • openid – User openid.
  • access_token – function get_access_token returns.
返回:

Bool.

wego.api.official_get_global_access_token(self)[源代码]

Get global access token.

参数:self – Call self.get_global_access_token() for get global access token.
返回:
str:Global access token

Wechat Interface

class wego.wechat.WeChatApi(settings)[源代码]

WeChat Api just do one thing: give params to wechat and get the data what wechat return.

change_group_name(groupid, name)[源代码]

Change group name.

参数:
  • groupid – Group ID.
  • name – New name.
返回:

Raw data that wechat returns.

change_user_group(openid, groupid)[源代码]

Move user to a new group.

参数:
  • openid – User openid.
  • groupid – Group ID.
返回:

Raw data that wechat returns.

check_personalized_menu_match(user_id)[源代码]

Check whether personalized menu match is correct.

:param data:user_id :return:Raw data that wechat returns.

close_order(data)[源代码]

Get close_order info.

返回:Raw data that wechat returns.
create_conditional_menu(data)[源代码]

Create a conditional menu.

参数:data – Menu data.
返回:Raw data that wechat returns.
create_group(name)[源代码]

Create a user group.

参数:name – Group name.
返回:Raw data that wechat returns.
create_menu(data)[源代码]

Create a menu.

参数:data – Menu data.
返回:Raw data that wechat returns.
del_all_menus()[源代码]

Delete all menus, contain conditional menu.

::return: Raw data that wechat returns.

del_conditional_menu(menu_id)[源代码]

Delete conditional menus, contain conditional menu.

返回:Raw data that wechat returns.
del_group(groupid)[源代码]

Delete a group.

参数:groupid – Group id.
返回:Raw data that wechat returns.
download_bill(data)[源代码]

download bill

返回:Raw data that wechat returns.
get_access_token(code)[源代码]

Use code for get access token, refresh token, openid etc.

参数:code – A code see function get_code_url.
返回:Raw data that wechat returns.
get_all_groups()[源代码]

Get all user groups.

返回:Raw data that wechat returns.
get_article_summary(begin_date, end_date)[源代码]

Get article summary

:param data:begin_date, end_date :return :Raw data that wechat returns.

get_article_total(begin_date, end_date)[源代码]

Get article total

:param data:begin_date, end_date :return :Raw data that wechat returns.

get_code_url(redirect_url, state)[源代码]

Get the url which 302 jump back and bring a code.

参数:
  • redirect_url – Jump back url
  • state – Jump back state
返回:

url

get_global_access_token()[源代码]

Get global access token.

返回:Raw data that wechat returns.
get_menus()[源代码]

Get all menus.

返回:Raw data that wechat returns.
get_user_cumulate(begin_date, end_date)[源代码]

GET accumulation of user

:param date:begin_date, end_date :return:Raw data that wechat returns.

get_user_groups(openid)[源代码]

Get all a user groups.

返回:Raw data that wechat returns.
get_user_read(begin_date, end_date)[源代码]

Get user read

:param data:begin_date, end_date :return :Raw data that wechat returns.

get_user_read_hour(begin_date, end_date)[源代码]

Get user read hour

param data:begin_date, end_date return :Raw data that wechat return.

get_user_share(begin_date, end_date)[源代码]

Get user share

param data:begin_data,end_date return :Raw data that wechat return.

get_user_share_hour(begin_date, end_date)[源代码]

Get user share

param data:begin_date, end_date retur :Raw data that wechat return.

get_userinfo(openid)[源代码]

Get user info with global access token (content subscribe, language, remark and groupid).

参数:openid – User openid.
返回:Raw data that wechat returns.
get_userinfo_by_token(openid, access_token)[源代码]

Get user info with user access token (without subscribe, language, remark and groupid).

参数:
  • openid – User openid.
  • access_token – function get_access_token returns.
返回:

Raw data that wechat returns.

get_variation_number_of_user(begin_date, end_date)[源代码]

Get variation in number od user

:param data:begin_date, end_date :return:Raw data that wechat returns.

get_wechat_servers_list()[源代码]

Get wechat servers list

参数:data
返回:Raw data that wechat returns.
is_access_token_has_expired(sele, openid, access_token)[源代码]

Determine whether the user access token has expired

参数:
  • openid – User openid.
  • access_token – function get_access_token returns.
返回:

Raw data that wechat returns.

pay_report(data)[源代码]

report

返回:Raw data that wechat returns.
query_order(data)[源代码]

Get order query.

返回:Raw data that wechat returns.
query_refund(data)[源代码]

refund query

返回:Raw data that wechat returns.
refresh_access_token(refresh_token)[源代码]

Refresh user access token by refresh token.

参数:refresh_token – function get_access_token returns.
返回:Raw data that wechat returns.
refund_order(data)[源代码]

refund.

返回:Raw data that wechat returns.
set_user_remark(openid, remark)[源代码]

Set user remark.

参数:
  • openid – User openid.
  • remark – The remark you want to set.
返回:

Raw data that wechat returns.

wego.wechat.get_global_access_token(self)[源代码]

获取全局 access token

Settings Interface

wego.settings

default setting

class wego.settings.WegoSettings(data)[源代码]

Wego settings

wego.settings.check_settings(settings)[源代码]

check if settings is available

参数:settings – a dict.
返回:None
wego.settings.init(**kwargs)[源代码]

Init settings, get wechat config at https://mp.weixin.qq.com

参数:
  • 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).
返回:

WegoApi object.

返回类型:

WegoApi.

Exceptions

exception wego.exceptions.InitError[源代码]

An init error occurred.