java后台与ISO端app对接

一.加密

package com.tcwl.vsmp.utils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.codec.binary.Base64;

import net.sf.json.JSONObject;
// import sun.misc.BASE64Decoder;
// import sun.misc.BASE64Encoder;

/**
 * 加密转Json
 * 
 * @author
 */
public class JsonAndBaseUtils
{

    /**
     * 加密并转json
     * @param result  结果
     * @param obj 对象
     * @return 结果
     */
    public static String encrypt(Integer result, Object obj)
    {

        Map<String, Object> map;
        map = new HashMap<String, Object>();
        map.put("result", result);
        map.put("info", obj);
        String outcome = "";

        try
        {
            outcome = new Base64().encodeAsString(
                    JSONObject.fromObject(map).toString().getBytes("utf-8"))
                    .replaceAll("[\n\r]", "");

            // outcome = new BASE64Encoder()
            // .encode(JSONObject.fromObject(map).toString().getBytes("utf-8"))
            // .replaceAll("[\n\r]", "");
        }
        catch (UnsupportedEncodingException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return outcome;
    }

    //
    /**
     * 解密
     * @param obj 字符串
     * @return 结果
     * @throws UnsupportedEncodingException
     */
    public static String decoding(String obj)
            throws UnsupportedEncodingException
    {

        // System.out.println(obj);
        // System.out.println(obj.replace(" ", "+"));

        byte[] b = null;
        String result = "";
        try
        {
            b = new Base64().decode(obj.replace(" ", "+"));
            result = new String(b, "UTF-8");

            // b = new BASE64Decoder().decodeBuffer(obj.replace(" ", "+"));
            // result = new String(b, "UTF-8");
            // System.out.println(result);
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return URLDecoder.decode(result, "UTF-8");
    }

}

二.接口

package com.tcwl.vsmp.app;

import com.tcwl.vsmp.mortgage.utils.Jx;
import com.tcwl.vsmp.utils.JsonAndBaseUtils;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 苏凯
 * 2019-1-17
 */
@Controller
public class JXExecuteCotroller
{
    @RequestMapping("/JXExecute")
    @ResponseBody
    public String execute(HttpServletResponse response,HttpServletRequest request,
            @RequestParam("params") String params){
        String requestParams = "";
        if(params == null || params==""){
            String mssg = "{\"status\":\"params字段数据不能为空!\"}";

            return JsonAndBaseUtils.encrypt(0, mssg);
        }
        Map<String,String> formdata = new HashMap<String,String>();
        String msg = "";
        int i = 1;
        try
        {
            requestParams = JsonAndBaseUtils.decoding(params);
            JSONObject json = JSONObject.fromObject(requestParams);
            //客户编号
            formdata.put("customer_code", json.getString("customer_code").toString());
            //order_no:订单号
            formdata.put("order_no", json.getString("order_no").toString());
            //利息 本金的千分之三
            formdata.put("interest_amt", json.getString("interest_amt").toString());
            //本金
            formdata.put("principal_amt", json.getString("principal_amt").toString());
            //账号管理费 利息加本金的 千分之三;即 (interest_amt+principal_amt)*0.003 = service_amt
            formdata.put("service_amt", json.getString("service_amt").toString());
            //还款金额 service_amt+principal_amt+interest_amt = total_sum
            formdata.put("total_sum", json.getString("total_sum").toString());
            //还款时间
            formdata.put("repay_time", json.getString("repay_time").toString());
             msg = Jx.execute1(formdata);
        }

        catch (Exception e)
        {
            e.printStackTrace();
            msg = "{\"status\":\"调取接口返回异常!\"}";
            i = 0;
        }
        return JsonAndBaseUtils.encrypt(i, msg);

    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_无往而不胜_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值