CallBackContorll.java 23.4 KB
Newer Older
翁国栋 committed
1 2
package cn.timer.api.controller.insure;

翁国栋 committed
3
import cn.timer.api.bean.insure.*;
翁国栋 committed
4
import cn.timer.api.bean.yggl.YgglMainEmp;
翁国栋 committed
5
import cn.timer.api.config.exception.CustomException;
翁国栋 committed
6
import cn.timer.api.utils.HttpUtils;
翁国栋 committed
7
import cn.timer.api.utils.ResultUtil;
翁国栋 committed
8 9
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
翁国栋 committed
10
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
翁国栋 committed
11
import com.google.common.collect.Lists;
翁国栋 committed
12 13
import com.google.common.collect.Maps;
import com.mysql.cj.util.StringUtils;
翁国栋 committed
14 15
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
翁国栋 committed
16
import io.swagger.models.auth.In;
翁国栋 committed
17
import org.apache.commons.codec.digest.DigestUtils;
翁国栋 committed
18 19
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
翁国栋 committed
20
import org.springframework.beans.factory.annotation.Value;
翁国栋 committed
21 22
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
翁国栋 committed
23
import org.springframework.web.servlet.ModelAndView;
翁国栋 committed
24

翁国栋 committed
25 26 27 28 29 30
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;
import java.util.Map;
翁国栋 committed
31
import java.util.Random;
翁国栋 committed
32 33 34 35 36 37 38 39 40 41 42 43

/**
 * @Description TODO
 * @Author wgd
 * @Date 2022/3/3 8:45
 */
@Api(tags = "8.0回调接口")
@RestController
@Transactional
@RequestMapping(value = "/callBack/policy", produces = {"application/json"})
public class CallBackContorll {
    private static final Logger log = LoggerFactory.getLogger(CallBackContorll.class);
翁国栋 committed
44 45 46 47
    @Value("${insure.appid}")
    private String appid;
    @Value("${insure.secret}")
    private String secret;
翁国栋 committed
48
    /*保全测试用*/
翁国栋 committed
49 50 51 52 53
    @Value("${insure.appidq}")
    private String appidq;
    @Value("${insure.secretq}")
    private String secretq;

翁国栋 committed
54 55 56
    @Value("${insure.getPolicyUrl}")
    private String getPolicyUrl;

翁国栋 committed
57 58
    @Value("${BASE_API_URL}")
    private String base_api_url;
翁国栋 committed
59

翁国栋 committed
60 61 62 63
    /*保全支付*/
    @Value("${insure.batchToPayUrl}")
    private String batchToPayUrl;

翁国栋 committed
64

翁国栋 committed
65 66 67 68
    /*支付回调*/
    @Value("${pay_page}")
    private String payPage;

翁国栋 committed
69
    @PostMapping(value = "/insuredCallBack")
翁国栋 committed
70
    @ApiOperation(value = "6.投保核保回调-弃用", httpMethod = "POST", notes = "投保申请回调")
翁国栋 committed
71 72
    private Map insuredCallBack(HttpServletRequest request, @RequestParam String pid, @RequestParam String sign, @RequestParam String timestamp) throws IOException {
        Map map = Maps.newHashMap();
翁国栋 committed
73 74
        map.put("status", "error");
        if (StringUtils.isNullOrEmpty(pid) || StringUtils.isNullOrEmpty(sign) && StringUtils.isNullOrEmpty(timestamp)) {
翁国栋 committed
75 76
            return map;
        }
翁国栋 committed
77
        if (!pid.equals(appidq)) {
翁国栋 committed
78 79 80 81 82 83
            return map;
        }
        InputStream is = null;
        is = request.getInputStream();
        StringBuilder sb = new StringBuilder();
        byte[] b = new byte[4096];
翁国栋 committed
84
        for (int n; (n = is.read(b)) != -1; ) {
翁国栋 committed
85 86 87
            sb.append(new String(b, 0, n));
        }
        String value = DigestUtils.md5Hex(appidq + secretq + timestamp + sb.toString());
翁国栋 committed
88
        if (!value.equals(sign)) {
翁国栋 committed
89 90
            return map;
        }
翁国栋 committed
91
        CallBack callBack = JSONObject.parseObject(sb.toString(), CallBack.class);
翁国栋 committed
92
        Map trueMap = Maps.newHashMap();
翁国栋 committed
93
        trueMap.put("status", "1");
翁国栋 committed
94
        return trueMap;
翁国栋 committed
95 96
    }

翁国栋 committed
97 98
    @PostMapping(value = "/addpPayCallBack")
    @ApiOperation(value = "11.增员核保回调", httpMethod = "POST", notes = "增员核保回调")
翁国栋 committed
99
    @Transactional(rollbackFor = Exception.class)
翁国栋 committed
100
    public Map addpPayCallBack(HttpServletRequest request, @RequestParam String pid, @RequestParam String sign, @RequestParam String timestamp)  {
翁国栋 committed
101 102
        /*核保*/
        /*如果是在线支付的话*/
翁国栋 committed
103
        Map map = Maps.newHashMap();
翁国栋 committed
104 105
        map.put("status", "error");
        if (StringUtils.isNullOrEmpty(pid) || StringUtils.isNullOrEmpty(sign) && StringUtils.isNullOrEmpty(timestamp)) {
翁国栋 committed
106 107
            return map;
        }
翁国栋 committed
108
        if (!pid.equals(appidq)) {
翁国栋 committed
109 110
            return map;
        }
翁国栋 committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
        try {
            InputStream is = null;
            is = request.getInputStream();
            StringBuilder sb = new StringBuilder();
            byte[] b = new byte[4096];
            for (int n; (n = is.read(b)) != -1; ) {
                sb.append(new String(b, 0, n));
            }
            String value = DigestUtils.md5Hex(pid + secretq + timestamp + sb.toString());
            if (!value.equals(sign)) {
                throw new CustomException("增员核保回调验签失败");
            }
            CallBack callBack = JSONObject.parseObject(sb.toString(), CallBack.class);
            if (callBack.getCallback_type().equals("1")) {
                List<InsureUser> insureUserList = InsureUser.builder().build().selectList(new QueryWrapper<InsureUser>().lambda().eq(InsureUser::getTransId, callBack.getOrder_import_info().getThird_uuid()));
                InsurePolicy insurePolicy = InsurePolicy.builder().id(insureUserList.get(0).getPolicyId()).build().selectById();
                if (callBack.getStatus().equals("1")) {
                    if (insureUserList.size() > 0) {
                        insurePolicy.setStatus("4");/*设置为支付状态*/
                        insurePolicy.setUpdateTime(new Date());
                        InsurePay insurePay = InsurePay.builder().payStatus(1).
                                serialNumber(callBack.getOrder_import_info().getUuid()).policyId(insurePolicy.getId()).amount(Double.parseDouble(callBack.getOrder_import_info().getTotal_money())).build();
                        insurePay.insert();
                        insurePolicy.setPayId(insurePay.getId());
                        insurePolicy.updateById();
翁国栋 committed
136

翁国栋 committed
137
                    }
翁国栋 committed
138 139 140
                    InsureLog.builder().type(7)
                            .requestData(sb.toString()).createTime(new Date()).requestType(1).returnBody(JSONObject.toJSONString(callBack)).requestPath(base_api_url + "/callBack/policy/addpPayCallBack")
                            .returnCode(callBack.getStatus()).returnMsg("核保通过").policyId(insurePolicy.getId()).build().insert();
翁国栋 committed
141
                } else {
翁国栋 committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
                    insureUserList.stream().forEach(v -> {
                        v.setStatus("2");
                        v.setInsureStatus(2);
                        v.updateById();
                    });
                    insurePolicy.setStatus("1");
                    insurePolicy.updateById();
                    List<Map> errMap = callBack.getOrder_import_info().getErr_list();
                    String errorMsg = "";
                    if (errMap.size() > 0) {
                        for (int i = 0; i < errMap.size(); i++) {
                            errorMsg = errorMsg + ("姓名:" + errMap.get(i).get("name").toString() + ",错误:" + errMap.get(i).get("err_content").toString() + ',');
                        }
                    } else {
                        errorMsg = callBack.getErr_msg();
                    }
                    //TODO 写入日志
                    InsureLog.builder().type(7)
                            .requestData(sb.toString()).createTime(new Date()).requestType(1).returnBody(JSONObject.toJSONString(callBack)).requestPath(base_api_url + "/callBack/policy/addpPayCallBack")
                            .returnCode(callBack.getStatus()).returnMsg(errorMsg).policyId(insurePolicy.getId()).build().insert();
翁国栋 committed
162
                }
翁国栋 committed
163
            }
翁国栋 committed
164
        } catch (Exception e) {
翁国栋 committed
165
            log.error("增员核保回调异常:",e);
翁国栋 committed
166 167 168 169 170
            throw new CustomException("增员核保回调异常");
        } finally {
            Map trueMap = Maps.newHashMap();
            trueMap.put("status", "1");
            return trueMap;
翁国栋 committed
171 172
        }
    }
翁国栋 committed
173

翁国栋 committed
174 175
    @PostMapping(value = "/CallBack")
    @ApiOperation(value = "7.保全增员申请回调", httpMethod = "POST", notes = "投保申请回调")
翁国栋 committed
176
    @Transactional(rollbackFor = Exception.class)
翁国栋 committed
177
    public Map callBack(HttpServletRequest request, @RequestParam String pid, @RequestParam String sign, @RequestParam String timestamp)  {
翁国栋 committed
178 179 180 181 182 183 184 185
        Map map = Maps.newHashMap();
        map.put("status", "error");
        if (StringUtils.isNullOrEmpty(pid) || StringUtils.isNullOrEmpty(sign) && StringUtils.isNullOrEmpty(timestamp)) {
            return map;
        }
        if (!pid.equals(appidq)) {
            return map;
        }
翁国栋 committed
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
        try {
            InputStream is = null;
            is = request.getInputStream();
            StringBuilder sb = new StringBuilder();
            byte[] b = new byte[4096];
            for (int n; (n = is.read(b)) != -1; ) {
                sb.append(new String(b, 0, n));
            }
            String value = DigestUtils.md5Hex(pid + secretq + timestamp + sb.toString());
            if (!value.equals(sign)) {
                throw new CustomException("保全增员申请回调验签失败");
            }
            Map paramsMap = Maps.newHashMap();
            paramsMap.put("pid", pid);
            paramsMap.put("timestamp", timestamp);
            paramsMap.put("sign", sign);
            CallBack callBack = JSONObject.parseObject(sb.toString(), CallBack.class);
翁国栋 committed
203 204 205 206
            List<InsureUser> list = InsureUser.builder().build().selectList(new QueryWrapper<InsureUser>().lambda().eq(InsureUser::getTransId, callBack.getOrder_import_info().getThird_uuid()));
            if(list.size()<=0){
                list = InsureUser.builder().build().selectList(new QueryWrapper<InsureUser>().lambda().eq(InsureUser::getBatchNo, callBack.getOrder_import_info().getUuid()));
            }
翁国栋 committed
207 208 209 210 211
            InsurePolicy insurePolicy = InsurePolicy.builder().build().selectOne(new QueryWrapper<InsurePolicy>().lambda().eq(InsurePolicy::getPolicyNo, list.get(0).getPolicyNo()));
            if (callBack.getStatus().equals("1")) {
                list.forEach(i -> {
                    i.setInsureStatus(1);
                    i.setStatus("1");
翁国栋 committed
212
                    i.updateById();
翁国栋 committed
213
                    YgglMainEmp.builder().isInsure(1).build().update(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getId, i.getUserId()));
翁国栋 committed
214
                });
翁国栋 committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
                List<InsureUser> oldlist = InsureUser.builder().build().selectList(new QueryWrapper<InsureUser>().lambda().eq(InsureUser::getReplaceTransId, callBack.getOrder_import_info().getUuid()));
                if (oldlist != null && oldlist.size() > 0) {
                    oldlist.forEach(i -> {
                        i.setInsureStatus(4);
                        i.setStatus("2");
                        i.updateById();
                        YgglMainEmp.builder().isInsure(0).build().update(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getId, i.getUserId()));
                    });
                }
                if (oldlist == null || oldlist.size() == 0) {
                    insurePolicy.setTotalPremium(String.valueOf(Double.valueOf(insurePolicy.getTotalPremium()) + Double.valueOf(callBack.getOrder_import_info().getTotal_money())));
                }
                insurePolicy.setPolicyFile(callBack.getOrder_import_info().getEndorsement_file());
                InsureLog.builder().requestParam(JSONObject.toJSONString(paramsMap)).type(7)
                        .requestData(sb.toString()).createTime(new Date()).requestType(1).returnBody(JSONObject.toJSONString(callBack)).requestPath(base_api_url + "/callBack/policy/CallBack")
翁国栋 committed
230
                        .returnCode(callBack.getStatus()).returnMsg("保单增员-更新成功").policyId(insurePolicy.getId()).build().insert();
翁国栋 committed
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
            } else {
                String errorMsg = "";
                InsureLog insureLog = InsureLog.builder().build().selectOne(new QueryWrapper<InsureLog>().lambda().eq(InsureLog::getTransId, callBack.getOrder_import_info().getThird_uuid()));
                if(callBack.getOrder_import_info().getErr_list()!=null) {
                    List<Map> errMap = callBack.getOrder_import_info().getErr_list();
                    if (errMap.size() > 0) {
                        for (int i = 0; i < errMap.size(); i++) {
                            errorMsg = errorMsg + ("姓名:" + errMap.get(i).get("name").toString() + ",错误:" + errMap.get(i).get("err_content").toString() + ',');
                        }
                    } else {
                        errorMsg = callBack.getErr_msg();
                    }
                }
                /*在保司系统点击取消申报时候会回调申报失败*/
                if(StringUtils.isNullOrEmpty(callBack.getOrder_import_info().getSingle_serial_no())){
                    list.forEach(i -> {
                        i.setInsureStatus(2);
                        i.setStatus("2");
                        i.updateById();
                        YgglMainEmp.builder().isInsure(0).build().update(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getId, i.getUserId()));
                    });
                }
                //TODO 写入日志
                InsureLog.builder().requestParam(JSONObject.toJSONString(paramsMap)).type(7)
                        .requestData(sb.toString()).createTime(new Date()).requestType(1).returnBody(JSONObject.toJSONString(callBack)).requestPath(base_api_url + "/callBack/policy/CallBack")
                        .returnCode(callBack.getStatus()).returnMsg(errorMsg).policyId(insurePolicy.getId()).build().insert();
翁国栋 committed
257
            }
翁国栋 committed
258
            /*无论此次申请成功还是失败这笔单都需要重新申报*/
翁国栋 committed
259 260 261
            insurePolicy.setUpdateTime(new Date());
            insurePolicy.setStatus("1");
            insurePolicy.updateById();
翁国栋 committed
262 263

        } catch (Exception e) {
翁国栋 committed
264
            log.error("保全增员申请回调异常:",e);
翁国栋 committed
265 266 267 268 269
            throw new CustomException("保全增员申请回调异常");
        } finally {
            Map trueMap = Maps.newHashMap();
            trueMap.put("status", "1");
            return trueMap;
翁国栋 committed
270
        }
翁国栋 committed
271

翁国栋 committed
272

翁国栋 committed
273
    }
翁国栋 committed
274 275 276

    @GetMapping(value = "/payStatus")
    @ApiOperation(value = "8.支付完成跳转", httpMethod = "GET", notes = "用于支付时跳回我们系统更新状态")
翁国栋 committed
277
    @Transactional(rollbackFor = Exception.class)
翁国栋 committed
278
    public ModelAndView callBackPayStatus(HttpServletRequest request, @RequestParam Integer policyId)  {
翁国栋 committed
279 280 281 282
        InsurePolicy insurePolicy = InsurePolicy.builder().id(policyId).build().selectById();
        InsurePay insurePay = InsurePay.builder().id(insurePolicy.getPayId()).build().selectById();
        insurePay.setPayTime(new Date());
        insurePay.updateById();
翁国栋 committed
283 284
        InsureLog.builder().type(7).createTime(new Date()).requestType(2).requestPath(base_api_url + "/callBack/policy/payStatus?policyId=" + policyId)
                .returnCode("suc").returnMsg("用户已支付" + insurePay.getAmount() + "元,等待更新保单状态").policyId(policyId).build().insert();
翁国栋 committed
285
        ModelAndView mav = new ModelAndView();
翁国栋 committed
286
        mav.setViewName("redirect:" + payPage + "/#/payPage?amount="+insurePay.getAmount());
翁国栋 committed
287
        return mav;
翁国栋 committed
288 289 290 291
    }

    @PostMapping(value = "/payCallBack")
    @ApiOperation(value = "9.投保支付收银台回调", httpMethod = "POST", notes = "支付完成跳转")
翁国栋 committed
292
    @Transactional(rollbackFor = Exception.class)
翁国栋 committed
293
    public Map payCallBack(HttpServletRequest request, @RequestParam String pid, @RequestParam String sign, @RequestParam String timestamp)  {
翁国栋 committed
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
        try {
            InputStream is = null;
            is = request.getInputStream();
            StringBuilder sb = new StringBuilder();
            byte[] b = new byte[4096];
            for (int n; (n = is.read(b)) != -1; ) {
                sb.append(new String(b, 0, n));
            }
            String value = DigestUtils.md5Hex(pid + secret + timestamp + sb.toString());
            if (!value.equals(sign)) {
                throw new CustomException("投保支付收银台回调验签失败");
            }
            PayCallBack callBack = JSONObject.parseObject(sb.toString(), PayCallBack.class);
            InsurePay insurePay = InsurePay.builder().build().selectOne(new QueryWrapper<InsurePay>().lambda().eq(InsurePay::getSerialNumber, callBack.getSerial_number()));
            insurePay.setAmount(Double.valueOf(callBack.getAmount()));
            insurePay.setPayStatus(Integer.parseInt(callBack.getPay_status()));
            insurePay.setPaySerialNo(callBack.getPay_serial_no());
            insurePay.setSerialNumber(callBack.getSerial_number());
            insurePay.setPayType(callBack.getPay_type());
            insurePay.updateById();
            InsureLog.builder().type(7).createTime(new Date()).requestType(1).requestPath(base_api_url + "/callBack/policy/payCallBack")
                    .returnCode("suc").returnMsg("确认支付成功,支付方式:" + insurePay.getPayType() + ",支付金额:" + callBack.getAmount()).policyId(insurePay.getPolicyId()).build().insert();
            /*调用出单接口更新保单状态*/
            Map paramsMap = Maps.newHashMap();
            paramsMap.put("pid", pid);
            paramsMap.put("timestamp", timestamp);
            paramsMap.put("sign", sign);
            Map bodyMap = Maps.newHashMap();
            bodyMap.put("quotation_id", callBack.getSerial_number());
            String data = HttpUtils.sendPost(getPolicyUrl, InsureContorll.setParams(JSONObject.toJSONString(bodyMap), appid, secret), bodyMap);
            Map dataMap = JSONObject.parseObject(data, Map.class);
            if (dataMap.size() > 0) {
                if (dataMap.get("errcode").toString().equals("suc") || dataMap.get("errcode").toString().equals("e25")) {
                    //TODO 如果是E25则将保单设为出单中,更新交由保单出单回调做,设为出单状态是因为之后可以手动校验
                    InsurePolicy insurePolicy = InsurePolicy.builder().id(insurePay.getPolicyId()).build().selectById();
                    insurePolicy.setStatus("2");
                    insurePolicy.setUpdateTime(new Date());
                    insurePolicy.updateById();
                }
                InsureLog.builder().requestParam(JSONObject.toJSONString(InsureContorll.setParams(JSONObject.toJSONString(bodyMap), appid, secret))).type(7)
翁国栋 committed
334
                        .requestData(JSONObject.toJSONString(bodyMap)).createTime(new Date()).requestType(1).returnBody(data).requestPath(getPolicyUrl)
翁国栋 committed
335
                        .returnCode(dataMap.get("errcode").toString()).policyId(insurePay.getPolicyId()).returnMsg(dataMap.get("errmsg").toString()).build().insert();
翁国栋 committed
336
            }
翁国栋 committed
337
        } catch (Exception e) {
翁国栋 committed
338
            log.error("投保支付收银台回调异常:",e);
翁国栋 committed
339 340 341 342 343
            throw new CustomException("投保支付收银台回调异常");
        } finally {
            Map map = Maps.newHashMap();
            map.put("status", "1");
            return map;
翁国栋 committed
344 345 346 347 348
        }
    }

    @PostMapping(value = "/issueCallback")
    @ApiOperation(value = "10.保单出单回调", httpMethod = "POST", notes = "支付完成跳转")
翁国栋 committed
349
    @Transactional(rollbackFor = Exception.class)
翁国栋 committed
350
    public Map issueCallback(HttpServletRequest request, @RequestParam String pid, @RequestParam String sign, @RequestParam String timestamp)  {
翁国栋 committed
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
        try {
            InputStream is = null;
            is = request.getInputStream();
            StringBuilder sb = new StringBuilder();
            byte[] b = new byte[4096];
            for (int n; (n = is.read(b)) != -1; ) {
                sb.append(new String(b, 0, n));
            }
            String value = DigestUtils.md5Hex(pid + secret + timestamp + sb.toString());
            if (!value.equals(sign)) {
                throw new CustomException("保单出单回调验签失败");
            }
            PolicyCallBack callBack = JSONObject.parseObject(sb.toString(), PolicyCallBack.class);
            InsurePay insurePay = InsurePay.builder().build().selectOne(new QueryWrapper<InsurePay>().lambda().eq(InsurePay::getSerialNumber, callBack.getSerial_number()));
            InsurePolicy insurePolicy = InsurePolicy.builder().id(insurePay.getPolicyId()).build().selectById();
            List<InsureUser> userList = InsureUser.builder().build().selectList(new QueryWrapper<InsureUser>().lambda().eq(InsureUser::getPolicyId, insurePolicy.getId()));
            insurePolicy.setUpdateTime(new Date());
            if (callBack.getStatus().equals("1")) {
                insurePay.setPayStatus(2);
                insurePolicy.setPolicyNo(callBack.getPolicy_no());
                insurePolicy.setTotalPremium(callBack.getTotal_premium());
                insurePolicy.setPolicyFile(callBack.getPolicy_file());
                insurePolicy.setStatus("1");
                insurePolicy.setKitUrl(callBack.getKit_url());
                userList.forEach(u -> {
                    u.setStatus("1");
                    u.setInsureStatus(1);
                    u.updateById();
                });
            } else {
                insurePay.setPayStatus(3);
                insurePolicy.setStatus("3");
                userList.forEach(u -> {
                    u.setStatus("2");
                    u.setInsureStatus(2);
                    u.updateById();
                });
            }
            insurePolicy.updateById();
            insurePay.updateById();
            InsureLog.builder().type(7).createTime(new Date()).requestType(1).returnBody(sb.toString()).requestPath(getPolicyUrl)
                    .returnCode(callBack.getStatus()).policyId(insurePay.getPolicyId()).returnMsg(callBack.getErr_msg()).build().insert();
        } catch (Exception e) {
翁国栋 committed
394
            log.error("保单出单回调:",e);
翁国栋 committed
395 396 397 398
            throw new CustomException("保单出单回调");
        } finally {
            Map map = Maps.newHashMap();
            map.put("status", "1");
翁国栋 committed
399 400
            return map;
        }
翁国栋 committed
401 402 403
    }

    @PostMapping(value = "/batchPayCallback")
翁国栋 committed
404
    @ApiOperation(value = "增员支付回调", httpMethod = "POST", notes = "增员支付回调")
翁国栋 committed
405
    @Transactional(rollbackFor = Exception.class)
翁国栋 committed
406
    public Map batchPayCallback(HttpServletRequest request,@RequestParam String pid, @RequestParam String sign, @RequestParam String timestamp)  {
翁国栋 committed
407 408 409 410 411 412 413 414 415

        try {
            InputStream is = null;
            is = request.getInputStream();
            StringBuilder sb = new StringBuilder();
            byte[] b = new byte[4096];
            for (int n; (n = is.read(b)) != -1; ) {
                sb.append(new String(b, 0, n));
            }
翁国栋 committed
416
            String value = DigestUtils.md5Hex(pid + secretq + timestamp + sb.toString());
翁国栋 committed
417 418 419
            if (!value.equals(sign)) {
                throw new CustomException("增员支付回调验签失败");
            }
翁国栋 committed
420 421 422 423 424 425 426 427 428 429 430
            BatchPayCallBack callBack = JSONObject.parseObject(sb.toString(), BatchPayCallBack.class);
            InsurePay insurePay = InsurePay.builder().build().selectOne(new QueryWrapper<InsurePay>().lambda().eq(InsurePay::getSerialNumber, callBack.getOrder_import_uuid()));
            if (insurePay != null) {
                insurePay.setPayStatus(Integer.parseInt(callBack.getPay_status()));
                insurePay.setAmount(Double.parseDouble(callBack.getPay_money()));
                insurePay.setPayType(callBack.getMethod());
                insurePay.updateById();
            }
            InsureLog.builder().type(7).createTime(new Date()).requestType(1).returnBody(sb.toString()).requestPath(base_api_url + "/callBack/policy/batchPayCallback")
                    .returnCode(callBack.getPay_status()).policyId(insurePay.getPolicyId()).returnMsg("确认支付成功,支付方式:" + insurePay.getPayType() + ",支付金额:" + insurePay.getAmount()).build().insert();
        } catch (Exception e) {
翁国栋 committed
431
            log.error("增员支付回调异常:",e);
翁国栋 committed
432 433 434 435 436
            throw new CustomException("增员支付回调异常");
        } finally {
            Map map = Maps.newHashMap();
            map.put("status", "1");
            return map;
翁国栋 committed
437 438
        }
    }
翁国栋 committed
439
}