zoukankan      html  css  js  c++  java
  • 【django创建支付对象】不限于任何第三方支付接入SDK

    #  根据第三方支付平台的SKD开发文档进行,只是个示例(但是都差不多)
    
    设置完第三方支付平台的公钥,与转换好的私钥后进行:
    
    # 充值通道
    class Alipay(APIView):
    
        # 返回支付链接
        def post(self,request):
            message = {}
            try:
                with transaction.atomic():
                    # 充值金额
                    recharge_money = float(request.data.get("money"))
    
                    # 订单编号
                    out_trade_no = "66" + str(datetime.datetime.fromtimestamp(time.time())).replace("-","").replace(" ","").replace(":","").replace(".","")
    
                    # 建议在服务启动时初始化  以下的参数一定是你接入的SKD说明文档的示例代码 
                    config_info = {
                        "api_key": cont.api_key,   
                        "mock_api_key": cont.mock_api_key,
                        "private_key": cont.private_key   # 一定会有个公钥转换成私钥VALUES 这个根据平台给定的规则进行转换后填入
                    }
                    adapay.mer_configs = {
                        "merchant1": config_info
                    }
    
                    # 创建订单请求  以下也是平台的SKD说明代码示例
                    payment = adapay.Payment.create(
                        order_no=out_trade_no,
                        app_id='你平台账号的APPID',
                        pay_channel='alipay',    # 肯定会有个选择是H5支付,APP支付,扫码支付等
                        pay_amt=str(recharge_money),
                        goods_title=cont.RECHARGE_MONEY,
                        goods_desc=cont.RECHARGE_MONEY,
                        notify_url=cont.notify_url_link,  # 回调接口 用于接收第三方支付服务器对用户支付的后的请求告知 告知已经支付完成(根据SKD提示接入)
                        mer_key='merchant1'
                    )
    
                    if payment['status'] == 'succeeded':
                        # 数据库创建充值订单    数据库的操作自己对应着自己的写就好了
                        models.PayRecord.objects.create(title=cont.RECHARGE_MONEY,
                                                        order_id=out_trade_no,
                                                        manner_pay="支付宝",
                                                        action = "+{}".format(recharge_money),
                                                        user_pay_id=request.auth,       # 付款用户
                                                        user_receive_id= request.auth,  # 到款用用户
                                                        )
    
                        message['order'] = out_trade_no
                        message['pay_id'] = payment['id']
                        message['code'] =  200
                        message['pay_url'] = payment['expend']['pay_info']
    return JsonResponse(message)
    
            except:
                # print(traceback.format_exc())
                msg = traceback.format_exc()
                logging_main.user_error.error(msg)
                message['code'] = 10014
                message['message'] = "请求异常"
                return JsonResponse(message)
  • 相关阅读:
    国内鲜为人知的“操作系统” Friend OS {Ep.1}
    好久没有发布什么内容了,今天推荐一个网站:Viritual x86
    温馨提示:yueming124.xyz的邮箱已经被我停用。
    Python
    Python -面试题
    码云-拉取远程代码
    mysql
    git 合并代码
    python 字典添加键值对 键相同值被覆盖的问题
    python 字典的减法
  • 原文地址:https://www.cnblogs.com/wanghong1994/p/14189293.html
Copyright © 2011-2022 走看看