充值接口 API 文档

优质
小牛编辑
127浏览
2023-12-01

充值接口API文档

接口定义

用户下单之后,兑吧会通过该接口向开发者发起一个虚拟商品的充值请求,开发者需在收到请求后处理该订单,为用户充值。

接口参数说明

输入参数(Get请求方式传参)

签名规则可参考文档MD5签名规则。对接过程中出现签名问题可通过签名排查工具进行自排查,其他问题,可参考文档 常见问题 处理

参数是否必须参数类型限制长度参数说明
appKeyyesstring255接口appKey,应用的唯一标识
orderNumyesstring255兑吧订单号(活动中奖领奖订单号)
developBizIdnostring255开发者订单号(免费活动抽奖中奖虚拟商品,该参数为空)
uidyesstring255用户唯一性标识,唯一且不可变
paramsyesstring255虚拟商品标识符
timestampyeslong201970-01-01开始的时间戳,毫秒。
signyesstring255签名,详见签名规则
descriptionyesstring255文案描述(来源活动名称)
accountnostring255用户兑换虚拟商品时输入的账号,只有在打开虚拟商品账号输入开关时,会传输此参数。

注:params为设置虚拟商品时的标识符,是虚拟商品的唯一编号,开发者充值接口依据标识符判断充值何种商品。

响应参数:

参数是否必须参数类型限制长度参数说明
statusyesstring255success成功,fail失败,process处理中
creditsnolong255用户当前最新积分(失败时候可以不传)
supplierBizIdyesstring255订单流水号,开发者返回给兑吧的凭据
errorMessageyesstring255status=fail返回的失败原因,成功可不填

响应示例:
成功:
{"status":"success","credits":"10", "supplierBizId":"no123456"}

处理中:
{"status":"process","credits":"10" , "supplierBizId":"no123456"}

失败:
{"status":"fail", "errorMessage":"签名签证失败", "supplierBizId":"no123456"}

代码示例


1.Java开发包

点击下载(java开发包)

如无法下载,请复制地址浏览器打开:https://github.com/duiba-Tech/duiba-java-sdk/archive/master.zip
/**
 * 虚拟商品充值解析
 * @param request
 * @return
 * @throws Exception 
 */
    public VirtualConsumeParams virtualCreditConsume(HttpServletRequest request) throws Exception{
        if(!appKey.equals(request.getParameter("appKey"))){
            throw new Exception("appKey不匹配");
        }
        if(request.getParameter("timestamp")==null){
            throw new Exception("请求中没有带时间戳");
        }
        boolean verify=SignTool.signVerify(appSecret, request);
        if(!verify){
            throw new Exception("签名验证失败");
        }
        VirtualConsumeParams params=new VirtualConsumeParams();
        params.setAppKey(appKey);
        params.setUid(request.getParameter("uid"));
        params.setSupplierBizId(request.getParameter("supplierBizId"));
        params.setTimestamp(new Date(Long.valueOf(request.getParameter("timestamp"))));
        params.setDescription(request.getParameter("description"));
        params.setOrderNum(request.getParameter("orderNum"));
        params.setParams(request.getParameter("params"));
        return params;
    }
2.PHP开发包

【点击下载】

/*
       *  虚拟商品充值请求的解析方法
       *  当用户兑换虚拟商品时,兑吧会发起虚拟商品充值请求,开发者收到请求后,可以通过此方法进行签名验证与解析,然后返回相应的格式
       *  返回格式为:
       *  成功:{"status":"success","credits":"10","supplierBizId":"no123546","errorMessage":""}
       *  处理中{"status":"process","credits":"10","supplierBizId":"no123546","errorMessage":""}
       * 失败:{"status":"fail","credits":"10","supplierBizId":"no123546","errorMessage":"余额不足"}
    */
    function parseVitrual($appKey,$appSecret,$request_array){
        if($request_array["appKey"] != $appKey){
            throw new Exception("appKey not match");
        }
        if($request_array["timestamp"] == null ){
            throw new Exception("timestamp can't be null");
        }
        $verify=signVerify($appSecret,$request_array);
        if(!$verify){
            throw new Exception("sign verify fail");
        }
        $ret=$request_array;
        return $ret;
    }
3.Python开发包

【点击下载】

 #虚拟商品充值请求接口解析
    def credits_virtual(self, request_params):
        if self.appKey != request_params['appKey']:
            raise Exception("appKey not match !")
        elif request_params["timestamp"] == '':
            raise Exception("timestamp can't be null ! ")
        elif self.signVerify(self.appSecret, request_params) == False:
            raise Exception("sign verify fail! ")
        else:
            return request_params