美文网首页
android &springboot body传递参数

android &springboot body传递参数

作者: 牵手生活 | 来源:发表于2020-01-02 16:01 被阅读0次

springboot的后端代码


    @ApiOperation(value = "微信数据-不包括message、snsInfo", notes = "微信数据-不包括message、snsInfo")

    @PostMapping("/api/wechatData/OptWechatDataNoMsgSns")
    @ResponseBody
    public IJSONResult OptWechatDataNoMsgSns(
            //公共参数部分
            @ApiParam(name="wechatid",value="微信原始id",required=true) @RequestHeader String wechatid
            ,@ApiParam(name="inviteCode",value="邀请码",required=true) @RequestHeader String  inviteCode
            ,@ApiParam(name="IMEI",value="设备IMEI",required=true) @RequestHeader String  imei
            ,@ApiParam(name="timestamp",value="时间戳10位",required=true) @RequestHeader String  timestamp
            ,@ApiParam(name="sign",value="参数签名",required=true) @RequestHeader String  sign

            //微信数据接口特有参数

            ,@ApiParam(name="content",value="微信数据的String字符串,对象或数组也请转为jsonStr",required=true) @RequestBody String  body


    ){


        logger.info("api 日志-头部 getClass().getName() ={} 的参数列表。wechatid ={};inviteCode = {};imei = {};timestamp ={};sign = {}",this.getClass().getName(),wechatid,inviteCode,imei,timestamp);
        logger.info("api 日志-param getClass().getName() ={} 的参数列表。content = {}",this.getClass().getName(),body);

        JSONObject jsonObject = JSON.parseObject(body);
        int dataType = jsonObject.getInteger("dataType");
        String content = jsonObject.getString("content");
        



        IJSONResult ijsonResult = IJSONResult.errorMsg("未知错误");


        return ijsonResult;
    }



}

postman的调试用例

image.png image.png

postman截图调用结果

android 代码--okgo


    static public void OptWechatDataNoMsgSns(int dateType,  BaseBean baseBean){{
        HashMap<String ,Object> hashMap = new HashMap<String,Object>();
        hashMap.put("dataType",dateType);
        hashMap.put("content",baseBean);

        OkGo.<CommonResponse<Object>>post(RetrofitClient.url+ "/wechatTask/api/wechatData/OptWechatDataNoMsgSns")
                .upJson(new Gson().toJson(hashMap))  //body json
                .headers("wechatid", "younghare")  //
                .headers("inviteCode", "invite6667")
                .headers("sign","")
                .headers("imei","IMEI343243432439")
                .headers("timestamp", String.valueOf(System.currentTimeMillis()))
                .execute(new JsonCallback<CommonResponse<Object>>() {
                    @Override
                    public void onError(Response<CommonResponse<Object>> response) {
                        super.onError(response);
                        Log.i("okgo","onError");
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        Log.i("okgo","onFinish");
                    }

                    @Override
                    public void onSuccess(Response<CommonResponse<Object>> response) {
                        Log.i("okgo","onSuccess");
                    }
                });

    }}

相关文章

网友评论

      本文标题:android &springboot body传递参数

      本文链接:https://www.haomeiwen.com/subject/hrjooctx.html