API 文档

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

API文档

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

参数是否必须参数类型限制长度参数说明
appKeyyesstring255接口appKey,应用的唯一标识
uidyesstring255用户标识,唯一且不可变
creditsyeslong20本次兑换增加的积分
typeyesstring40game(游戏), sign(签到),task(pk赛), reSign(补签)。 hdtool(加积分活动)所有类型不区分大小写
orderNumyesstring255兑吧订单号(请记录到数据库中)
timestampyesstring201970-01-01开始的时间戳,毫秒为单位。
descriptionnostring255本次增加积分的描述(带中文,请用utf-8进行url解码)
ipnostring255用户ip,不保证获取到
signyesstring255MD5签名,详见签名规则

响应参数

参数是否必须参数类型限制长度参数说明
statusyesstring255加积分结果状态,回复ok或者fail
errorMessagenostring255出错原因
bizIdyesstring255开发者的订单号(唯一且不重复,如果失败该值可以不传)
creditsyeslong20用户积分余额

请使用JSON格式响应

响应示例

成功:
{
 "status":"ok",
 "errorMessage":" ",
 "bizId":"test-20140730192133033",
 "credits":"120"
}
失败:
{
 "status":"fail",
 "errorMessage":"失败原因",
 "credits":"100"
}

代码示例


点击下载(java开发包)

如无法下载,请复制地址浏览器打开:https://github.com/duiba-Tech/duiba-java-sdk/archive/master.zip
/**
     * 加积分充值解析
     * @param request
     * @return
     * @throws Exception
     */
    public AddCreditsParams parseaddCredits(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("签名验证失败");
        }
        AddCreditsParams params=new AddCreditsParams();
        params.setAppKey(appKey);
        params.setUid(request.getParameter("uid"));
        params.setCredits(Long.valueOf(request.getParameter("credits")));
        params.setTimestamp(new Date(Long.valueOf(request.getParameter("timestamp"))));
        params.setDescription(request.getParameter("description"));
        params.setOrderNum(request.getParameter("orderNum"));
        params.setType(request.getParameter("type"));
        return params;
    }
2.PHP开发包

【点击下载】

/*
       *  加积分请求的解析方法
        *  返回格式为:
        *  {"status":"ok","credits":"10","bizId":"no123546","errorMessage":""}  或者
        *  {"status":"fail","credits":"10","errorMessage":"余额不足"}
    */
    function parseAddCredits($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 add_credits(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

#

更新记录 1.9-17type增加新类型task(PK赛)的类型