|
| 1 | +# |
| 2 | +# GOGO支付接入代码DEMO - python版本 |
| 3 | +# 感谢ys提供该demo,QQ:279124388 |
| 4 | +# |
| 5 | +# GOGO支付 - 更好的个人支付解决方案 |
| 6 | +# 官网: https://www.gogozhifu.com |
| 7 | +# QQ: 653107385 |
| 8 | +# 微信: gump994 |
| 9 | +# |
| 10 | + |
| 11 | +import requests |
| 12 | +import hashlib |
| 13 | +import time |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +class GoApiClient(object): |
| 18 | + def __init__(self, AppId, AppSecret , type ): |
| 19 | + self.AppId = AppId |
| 20 | + self.AppSecret = AppSecret |
| 21 | + self.tpye = type |
| 22 | + self.headers = {"App-Id": self.AppId, "App-Secret": self.AppSecret} |
| 23 | + |
| 24 | + def pay(self, method,param_json, **kwargs): |
| 25 | + params = param_json |
| 26 | + if self.tpye =='Create': |
| 27 | + params['sign'] = hashlib.md5((self.AppId + params['payId'] + params['param'] + params['type'] + params['price'] + self.AppSecret).encode('utf-8')).hexdigest() #创建订单时生成校验签名 |
| 28 | + resp = requests.post(method, params=params, **kwargs, headers=self.headers) |
| 29 | + print(resp.url) |
| 30 | + return (resp.text) |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +AppId = "你的appid" |
| 38 | +AppSecret = "你的AppSecret" |
| 39 | + |
| 40 | +client = GoApiClient(AppId, AppSecret,'Create') |
| 41 | +resp = client.pay("https://www.gogozhifu.com/shop/api/createOrder", #创建订单 |
| 42 | + { 'payId': time.strftime("%Y%m%d%H%M%S", time.localtime()) , #【必传】商户订单号,可以是时间戳,不可重复 |
| 43 | + 'type': '1' , #【必传】微信支付传入1 支付宝支付传入2 |
| 44 | + 'price': '50.00', #【必传】订单金额,保留两位小数的字符串,例如“1.00” |
| 45 | + 'param':'', #【可选】传输参数,将会原样返回到异步和同步通知接口 |
| 46 | + 'notifyUrl':'http://localhost/notify.php', #【可选】传入则设置该订单的异步通知接口为该参数,不传或传空则使用后台设置的接口 |
| 47 | + 'returnUrl':'http://localhost/return.php', #【可选】传入则设置该订单的同步跳转接口为该参数,不传或传空则使用后台设置的接口 |
| 48 | + 'title':'', #【可选】订单主题、类型,之后可根据该值统计分析数据,最多10个字符 |
| 49 | + 'isHtml':'1', #【可选】传入1则自动跳转到支付页面,否则返回创建结果的json数据 |
| 50 | + 'content':'', #【可选】描述订单具体内容、备注等说明文字 |
| 51 | + 'returnParam':'' #【可选】默认是0,传1即可让官方支付页跳转returnUrl带上回调通知的参数 |
| 52 | + } |
| 53 | + ) |
| 54 | + |
| 55 | +print(resp) |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +# |
| 60 | +# |
| 61 | +# client = GoApiClient(AppId, AppSecret ,'Inquire' ) |
| 62 | +# resp = client.pay("https://www.gogozhifu.com/getOrder", #查询订单信息 |
| 63 | +# {'orderId': '202110061010199251' #【必传】云端订单号,创建订单返回的 |
| 64 | +# }) |
| 65 | +# print(resp) |
| 66 | +# |
| 67 | +# |
| 68 | +# |
| 69 | +# client = GoApiClient(AppId, AppSecret ,'Inquire' ) |
| 70 | +# resp = client.pay("https://www.gogozhifu.com/checkOrder", #查询订单状态 |
| 71 | +# {'orderId': '202110032010346128' #【必传】云端订单号,创建订单返回的 |
| 72 | +# }) |
| 73 | +# print(resp) |
| 74 | +# |
| 75 | +# |
| 76 | +# client = GoApiClient(AppId, AppSecret ,'Inquire' ) |
| 77 | +# resp = client.pay("https://www.gogozhifu.com/closeOrder", #关闭订单 |
| 78 | +# {'orderId': '202110051310219985' |
| 79 | +# 'payId':'' |
| 80 | +# }) |
| 81 | +# print(resp) |
| 82 | +# |
| 83 | +# client = GoApiClient(AppId, AppSecret ,'Inquire' ) |
| 84 | +# resp = client.pay("https://www.gogozhifu.com/deleteOrder", #删除订单 |
| 85 | +# {'orderId': '202110061010199251', |
| 86 | +# 'payId':'20211006101819' |
| 87 | +# }) |
| 88 | +# print(resp) |
| 89 | + |
0 commit comments