public void setTotal_fee(BigDecimal total_fee) { if(total_fee!=null) { total_fee = NumberUtil.toCent(total_fee); } this.total_fee = total_fee; }
public BigDecimal getRefund_fee() { if(refund_fee!=null) { return NumberUtil.toYuan(refund_fee); } return refund_fee; }
public void setClientids(List<String> clientids) { for (String string : clientids) { if (StringUtil.isBlank(string)) continue; this.clientids.add(string); } }
/** * 获取sessionkey和openid,一般用于小程序授权登录. * 官方文档 https://developers.weixin.qq.com/miniprogram/dev/api/code2Session.html * @param code 小程序获取的code * @return * @throws MutilsErrorException */ public static Code2SessionReturnModel jscode2session(String code) throws MutilsErrorException { CloseableHttpClient build = HttpClientUtil.getInstance(); CloseableHttpResponse response = null; try { String url = "https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code"; url = url.replace("APPID", config.getAppid()).replace("SECRET", config.getAppSecret()).replace("JSCODE", code); HttpGet get = HttpClientUtil.getGetMethod(url); response = build.execute(get); HttpEntity entity = response.getEntity(); String string = EntityUtils.toString(entity); log.info("Code2SessionReturnModel string is {}", string); return JSON.parseObject(string, Code2SessionReturnModel.class); } catch (Exception e) { throw new MutilsErrorException(e, "小程序使用code换取openid等信息失败"); } finally { IOUtil.close(build, response); } }
/** * 获取小程序码 * 参考 https://developers.weixin.qq.com/miniprogram/dev/api/getWXACodeUnlimit.html * @param model * @return * @throws MutilsErrorException */ public static InputStream getMiniProgramQrCode(MiniProgramCodeModel model) throws MutilsErrorException { model.verificationField(); CloseableHttpClient httpClient = HttpClientUtil.getInstance(); CloseableHttpResponse response =null; try { HttpPost httpPost = HttpClientUtil.getPostMethod("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + model.getAccess_token()); // 接口 httpPost.addHeader(HTTP.CONTENT_TYPE, "application/json"); StringEntity entity = new StringEntity(model.toString()); entity.setContentType("image/png"); httpPost.setEntity(entity); response = httpClient.execute(httpPost); return response.getEntity().getContent(); } catch (Exception e) { throw new MutilsErrorException(e, "获取小程序码二维码失败"); }finally { IOUtil.close(httpClient,response); } } }
/** * 发起退款申请 * * @param model * @return * @throws MutilsErrorException */ protected static RefundReturnModel createRefundRequest(RefundModel model) throws MutilsErrorException { String xmlParam = model.toXml(payconfig.getPartnerKey()); log.info("refund xml is {}", xmlParam); CloseableHttpClient httpclient = null; CloseableHttpResponse response = null; try { httpclient = HttpClientUtil.getSSLInstance(payconfig.getPartnerId(), payconfig.getCertificatePath(), payconfig.getCertificateFormat()); HttpPost httpost = HttpClientUtil.getPostMethod(payconfig.getRefundUrl()); httpost.setEntity(new StringEntity(xmlParam, "UTF-8")); response = httpclient.execute(httpost); String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8"); log.info("refund json is {}", jsonStr); return MapUtil.mapToObject(ParseXmlUtil.doXMLParse(jsonStr), RefundReturnModel.class); } catch (Exception e) { throw new MutilsErrorException(e, "发起退款失败"); } finally { IOUtil.close(httpclient, response); } }
/** * 微信支付回调解析 * <xml><return_code><![CDATA[STATE]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml> * 如果成功 将STATE替换为SUCCESS 如果失败替换为FAIL 反馈给微信服务器不用再重复请求。 使用PrintWriter.println直接输出 * * @param req * @throws MutilsErrorException */ public static NotifyModel parseNotify(HttpServletRequest req) throws MutilsErrorException { BufferedReader br =null; InputStreamReader inputStreamReader =null; try { inputStreamReader = new InputStreamReader(req.getInputStream()); br = new BufferedReader(inputStreamReader); String line = null; StringBuilder sb = new StringBuilder(); while ((line = br.readLine()) != null) { sb.append(line); } br.close(); Map<String, String> map = ParseXmlUtil.doXMLParse(sb.toString()); return MapUtil.mapToObject(map, NotifyModel.class); } catch (Exception e) { throw new MutilsErrorException(e, "微信回调解析失败"); }finally { IOUtil.close(br,inputStreamReader); } }
/** * D://upload/aaa * * @param filename 无后缀的文件名 2018年10月11日 * @throws Exception */ public void export(String filename) throws MutilsErrorException { FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(filename + excelVersion.getSuffix()); workbook.write(fileOutputStream); } catch (Exception e) { throw new MutilsErrorException(e, "Excel读取失败!"); } finally { IOUtil.close(workbook, fileOutputStream); } }
public QuerySendDetailsRequest toQuerySendDetailsRequest() { this.verificationField(); QuerySendDetailsRequest querySendDetailsRequest = new QuerySendDetailsRequest(); querySendDetailsRequest.setCurrentPage(currentPage); querySendDetailsRequest.setPageSize(pageSize); querySendDetailsRequest.setPhoneNumber(phoneNumber); querySendDetailsRequest.setSendDate(DateUtil.date2String(sendDate, 3)); return querySendDetailsRequest; }
/** * 派发订单 /api/v3/order-send.json * * @return * @throws Exception */ public static JSONObject order_send(OrderModel ot) throws MutilsErrorException { return doSend("/api/v3/order-send.json", MapUtil.toMap(ot)); }
/** * 小程序获取accessToken * 详情参考 https://developers.weixin.qq.com/miniprogram/dev/api/getAccessToken.html * @return * @throws MutilsErrorException */ public static AccessTokenModel getAccessToken() throws MutilsErrorException { CloseableHttpClient instance = HttpClientUtil.getInstance(); CloseableHttpResponse response = null; try { String accessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET"; String requestUrl = accessTokenUrl.replace("APPID", config.getAppid()).replace("APPSECRET", config.getAppSecret()); HttpGet getMethod = HttpClientUtil.getGetMethod(requestUrl); response = instance.execute(getMethod); String string = EntityUtils.toString(response.getEntity(), "UTF-8"); getMethod.releaseConnection(); return JSON.parseObject(string, AccessTokenModel.class); } catch (Exception e) { throw new MutilsErrorException(e, "小程序获取AccessToken失败"); } finally { IOUtil.close(instance, response); } }
public void setAmount(BigDecimal amount) { if(amount!=null) { amount = NumberUtil.toCent(amount); } this.amount = amount; }
public void setClientids(String... clientids) { for (String string : clientids) { if (StringUtil.isBlank(string)) continue; this.clientids.add(string); } }
public BigDecimal getTotal_fee() { if(total_fee!=null) { return NumberUtil.toYuan(total_fee); } return total_fee; }
public void setRefund_fee(BigDecimal refund_fee) { if(refund_fee!=null) { refund_fee =NumberUtil.toCent(refund_fee); } this.refund_fee = refund_fee; }
/** * 生成xml * @return * @throws MutilsErrorException */ public String toXml(String partnerKey) throws MutilsErrorException { SortedMap<String, String> treeMap = toTreeMap(); String sign = SignUtil.createSign(treeMap, partnerKey); this.setSign(sign); StringBuffer sb = new StringBuffer("<xml>"); for (Field field : getAllFields()) { try { if(verificationField(field)) continue; field.setAccessible(true); Object object = field.get(this); if (!StringUtil.isBlank(object)) { sb.append("<").append(field.getName()).append(">"); sb.append(object).append("</").append(field.getName()).append(">"); } } catch (Exception e) { continue; } } return sb.append("</xml>").toString(); } }
public BigDecimal getTotal_fee() { if(total_fee!=null) { return NumberUtil.toYuan(total_fee); } return total_fee; }
public void setTotal_fee(BigDecimal total_fee) { if(total_fee!=null) { total_fee =NumberUtil.toCent(total_fee); } this.total_fee = total_fee; }
public BigDecimal getAmount() { if(amount!=null) { amount = NumberUtil.toYuan(amount); } return amount; }
public void setOrder_price(BigDecimal order_price) { if(order_price!=null) { order_price = NumberUtil.toCent(order_price); } this.order_price = order_price; }