| | |
| | | package com.kidgrow.oprationcenter.controller.weixin; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.kidgrow.common.model.ResultBody; |
| | | import com.kidgrow.common.utils.DateUtils; |
| | | import com.kidgrow.common.utils.QRCodeUtil; |
| | | import com.kidgrow.common.utils.StringUtils; |
| | | import com.kidgrow.oprationcenter.config.weixin.MyConfig; |
| | | import com.kidgrow.oprationcenter.config.weixin.WXPay; |
| | | import com.kidgrow.oprationcenter.config.weixin.WXPayUtil; |
| | | import com.kidgrow.oprationcenter.config.weixin.WeiXinOfficPayProperties; |
| | | import com.kidgrow.oprationcenter.model.SaasClientPay; |
| | | import com.kidgrow.oprationcenter.service.ISaasClientPayService; |
| | | import com.kidgrow.oprationcenter.service.WxService; |
| | | import com.kidgrow.oprationcenter.weixin.MyConfig; |
| | | import com.kidgrow.oprationcenter.weixin.WXPay; |
| | | import com.kidgrow.oprationcenter.weixin.WXPayUtil; |
| | | import com.kidgrow.oprationcenter.weixin.WeiXinOfficPayProperties; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.InputStream; |
| | | import java.util.*; |
| | | |
| | | |
| | |
| | | ISaasClientPayService iSaasClientPayService; |
| | | @Resource |
| | | WeiXinOfficPayProperties weiXinOfficPayProperties; |
| | | @Autowired |
| | | WxService wxService; |
| | | |
| | | @ApiOperation(value = "保存") |
| | | /** |
| | | * 测试微信的预支付接口 |
| | | * @param map |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @ApiOperation(value = "测试微信的预支付接口") |
| | | @PostMapping("pay") |
| | | public ResultBody save(@RequestBody Map<String,Object> map) throws Exception { |
| | | Long hospitalId = MapUtils.getLong(map, "hospitalId"); |
| | |
| | | if (doctorId!=null) { |
| | | return ResultBody.failed().data("请输入医生id"); |
| | | } |
| | | |
| | | if (diaId!=null) { |
| | | return ResultBody.failed().data("请输入诊断记录ID"); |
| | | } |
| | | Map<String,String> jsonObject=new HashMap<>(); |
| | | Map<String,Object> mapto=new HashMap<>(); |
| | | jsonObject.put("body","腾讯");//商品描述 |
| | | jsonObject.put("out_trade_no","20150806123434");//商户订单号 |
| | | jsonObject.put("out_trade_no",UUID.randomUUID().toString().replaceAll("-",""));//商户订单号 |
| | | jsonObject.put("total_fee","1");//标价金额 |
| | | jsonObject.put("spbill_create_ip","192.168.2.240");//终端IP |
| | | // jsonObject.put("notify_url",myConfig.getPayNotifyUrl());//通知地址 |
| | |
| | | } |
| | | SaasClientPay saasClientPay=new SaasClientPay(); |
| | | saasClientPay.setId(UUID.randomUUID().toString().replaceAll("_", "")); |
| | | saasClientPay.setCreateHospitalDepartment(""); |
| | | saasClientPay.setCreateHospitalDepartid(""); |
| | | saasClientPay.setCreateHospitalId(Long.valueOf(1L)); |
| | | saasClientPay.setPayPrice(1); |
| | | saasClientPay.setCreateHospitalName(""); |
| | | saasClientPay.setOutTradeNo(jsonObject.get("out_trade_no")); |
| | |
| | | saasClientPay.setPayStatus(0); |
| | | saasClientPay.setPayMethod(0); |
| | | saasClientPay.setDiaId("1"); |
| | | saasClientPay.setCreateTime(new Date()); |
| | | boolean save = iSaasClientPayService.saveOrUpdate(saasClientPay); |
| | | String s = QRCodeUtil.creatRrCode(resultStr, 200, 200, 0).replaceAll("\n","").replaceAll("\r",""); |
| | | return ResultBody.ok().data(s); |
| | | } |
| | | |
| | | /** |
| | | * 微信的回调接口 |
| | | * @param request |
| | | * @param response |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @RequestMapping("/callback") |
| | | public void OrderCallBack(HttpServletRequest request, HttpServletResponse response,Map<String,Object> map) throws Exception { |
| | | Map<String, String> requestMap = this.getRequestMap(request.getParameterMap()); |
| | | log.error("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"); |
| | | log.error(requestMap.toString()); |
| | | log.error("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"); |
| | | log.error(map.toString()); |
| | | log.error("eeeeeeeeeeeeeeeeeeeeee"); |
| | | if(WXPayUtil.isSignatureValid(requestMap, "GSFcX6WdgRTAS6154EW14WE3SGBSER49")){ |
| | | //支付成功 |
| | | if(requestMap.get("result_code").equals("SUCCESS")){ |
| | | //更新状态 out_trade_no |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq("out_trade_no",requestMap.get("out_trade_no")); |
| | | queryWrapper.eq("pay_status",0); |
| | | List<SaasClientPay> list = iSaasClientPayService.list(queryWrapper); |
| | | if(!list.isEmpty()){ |
| | | SaasClientPay saasClientPay = list.get(0); |
| | | saasClientPay.setPayTime(DateUtils.parseDate(requestMap.get("time_end"))); |
| | | saasClientPay.setPayStatus(2); |
| | | saasClientPay.setTradeNo(requestMap.get("transaction_id")); |
| | | boolean b = iSaasClientPayService.saveOrUpdate(saasClientPay); |
| | | } |
| | | } |
| | | }else { |
| | | System.out.println("验签失败"); |
| | | public String OrderCallBack(HttpServletRequest request, HttpServletResponse response) throws Exception { |
| | | InputStream inStream = request.getInputStream(); |
| | | ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); |
| | | byte[] buffer = new byte[1024]; |
| | | int len = 0; |
| | | while ((len = inStream.read(buffer)) != -1) { |
| | | outSteam.write(buffer, 0, len); |
| | | } |
| | | String resultxml = new String(outSteam.toByteArray(), "utf-8"); |
| | | Map<String, String> requestMap = WXPayUtil.xmlToMap(resultxml); |
| | | String callback = wxService.callback(requestMap); |
| | | return callback; |
| | | } |
| | | private Map<String,String> getRequestMap(Map<String,String[]> requestParams){ |
| | | Map<String,String> params = new HashMap<>(); |
| | | for (String name : requestParams.keySet()) { |
| | | String[] values = requestParams.get(name); |
| | | String valueStr = ""; |
| | | for (int i = 0; i < values.length; i++) { |
| | | valueStr = (i == values.length - 1) ? valueStr + values[i] |
| | | : valueStr + values[i] + ","; |
| | | } |
| | | params.put(name, valueStr); |
| | | System.out.println(name+" ==> "+valueStr); |
| | | } |
| | | return params; |
| | | } |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | WxController weixinController=new WxController(); |
| | | Map<String,Object> map=null; |