php 充值api接口,充值接口API文档

充值接口API文档

接口定义

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

接口参数说明

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

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

参数

是否必须

参数类型

限制长度

参数说明

appKey

yes

string

255

接口appKey,应用的唯一标识

orderNum

yes

string

255

兑吧订单号(活动中奖领奖订单号)

developBizId

no

string

255

开发者订单号(免费活动抽奖中奖虚拟商品,该参数为空)

uid

yes

string

255

用户唯一性标识,唯一且不可变

params

yes

string

255

虚拟商品标识符

timestamp

yes

long

20

1970-01-01开始的时间戳,毫秒。

sign

yes

string

255

签名,详见签名规则

description

yes

string

255

文案描述(来源活动名称)

account

no

string

255

用户兑换虚拟商品时输入的账号,只有在打开虚拟商品账号输入开关时,会传输此参数。

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

响应参数:

参数

是否必须

参数类型

限制长度

参数说明

status

yes

string

255

success成功,fail失败,process处理中

credits

no

long

255

用户当前最新积分(失败时候可以不传)

supplierBizId

yes

string

255

订单流水号,开发者返回给兑吧的凭据

errorMessage

yes

string

255

status=fail返回的失败原因,成功可不填

响应示例:

成功:

{"status":"success","credits":"10", "supplierBizId":"no123456"}

处理中:

{"status":"process","credits":"10" , "supplierBizId":"no123456"}

失败:

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

代码示例

1.Java开发包

/**

* 虚拟商品充值解析

* @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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值