22
33import hashlib
44
5- from pingpp import http_client , util
5+ from pingpp import http_client , util , proxy , ca_bundle
66from pingpp .six .moves .urllib .parse import urlencode , quote_plus
7+ from pingpp import verify_ssl_certs as verify
78
89
910class WxpubOauth :
@@ -23,11 +24,13 @@ def get_openid(app_id, app_secret, code):
2324 :return: openid 微信公众号授权用户唯一标识, 可用于微信网页内支付
2425 """
2526 url = WxpubOauth .create_oauth_url_for_openid (app_id , app_secret , code )
26- client = http_client .new_default_http_client ()
27- rbody , rcode = client .request ('GET' , url , {})
27+ client = http_client .new_default_http_client (
28+ verify_ssl_certs = verify , proxy = proxy , ca_bundle = ca_bundle )
29+ rbody , rcode , headers = client .request ('GET' , url , {})
2830 if rcode == 200 :
2931 data = util .json .loads (rbody )
30- return data ['openid' ]
32+ if 'openid' in data :
33+ return data ['openid' ]
3134
3235 return None
3336
@@ -88,24 +91,31 @@ def get_jsapi_ticket(app_id, app_secret):
8891 query_str = urlencode (data )
8992 access_token_url = \
9093 'https://api.weixin.qq.com/cgi-bin/token?' + query_str
91- client = http_client .new_default_http_client ()
92- rbody , rcode = client .request ('GET' , access_token_url , {})
94+ client = http_client .new_default_http_client (
95+ verify_ssl_certs = verify , proxy = proxy , ca_bundle = ca_bundle )
96+ rbody , rcode , headers = client .request ('GET' , access_token_url , {})
9397 rbody = util .json .loads (rbody )
9498 if rcode != 200 :
9599 return rbody
96100
101+ if 'access_token' not in rbody :
102+ return None
103+
97104 data = dict ()
98105 data ['access_token' ] = rbody ['access_token' ]
99106 data ['type' ] = 'jsapi'
100107 query_str = urlencode (data )
101108 jsapi_ticket_url = \
102109 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?' + query_str
103- client = http_client .new_default_http_client ()
104- rbody , rcode = client .request ('GET' , jsapi_ticket_url , {})
110+ client = http_client .new_default_http_client (
111+ verify_ssl_certs = verify , proxy = proxy , ca_bundle = ca_bundle )
112+ rbody , rcode , headers = client .request ('GET' , jsapi_ticket_url , {})
105113 data = util .json .loads (rbody )
106114 if rcode == 200 :
107115 return data
108116
117+ return None
118+
109119 @staticmethod
110120 def get_signature (charge , jsapi_ticket , url ):
111121 """
@@ -126,5 +136,5 @@ def get_signature(charge, jsapi_ticket, url):
126136 key .lower (),
127137 sign_dict [key ]
128138 ) for key in sorted (sign_dict )])
129- sign_dict [ 'signature' ] = hashlib . sha1 ( string ). hexdigest ()
130- return sign_dict [ 'signature' ]
139+
140+ return hashlib . sha1 ( string ). hexdigest ()
0 commit comments