Merge branch 'api' into order_reform
6 files added
3 files deleted
32 files modified
| | |
| | | if (task != null) { |
| | | // 消息内容 |
| | | if (StringUtils.isNotBlank(content)) { |
| | | LogUtil.info("本次发送消息task.getExchange()="+task.getExchange()+";routingKey="+routingKey+";content="+content); |
| | | channel.basicPublish(task.getExchange(), routingKey, false, null, content.getBytes()); |
| | | } else { |
| | | LogUtil.info("本次发送空消息"); |
| | |
| | | } |
| | | |
| | | Logger log=Logger.getLogger(HttpRequest.class); |
| | | |
| | | |
| | | //表示请求器是否已经做了初始化工作 |
| | | private boolean hasInit = false; |
| | | |
| | |
| | | |
| | | //HTTP请求器 |
| | | private CloseableHttpClient httpClient; |
| | | //证书地址 |
| | | private String certLocalPath; |
| | | //商户号 |
| | | private String mchId; |
| | | |
| | | public HttpsRequest2() throws UnrecoverableKeyException, KeyManagementException, NoSuchAlgorithmException, KeyStoreException, IOException { |
| | | init(); |
| | |
| | | |
| | | private void init() throws IOException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyManagementException { |
| | | |
| | | KeyStore keyStore = KeyStore.getInstance("PKCS12"); |
| | | FileInputStream instream = new FileInputStream(new File(WechatConfigure.certLocalPath));//加载本地的证书进行https加密传输 |
| | | KeyStore keyStore = KeyStore.getInstance("PKCS12"); |
| | | FileInputStream instream = new FileInputStream(new File(certLocalPath));//加载本地的证书进行https加密传输 |
| | | try { |
| | | keyStore.load(instream,WechatConfigure.certPassword.toCharArray());//设置证书密码 |
| | | keyStore.load(instream, mchId.toCharArray());//设置证书密码 |
| | | } catch (CertificateException e) { |
| | | e.printStackTrace(); |
| | | } catch (NoSuchAlgorithmException e) { |
| | |
| | | } |
| | | // Trust own CA and all self-signed certs |
| | | SSLContext sslcontext = SSLContexts.custom() |
| | | .loadKeyMaterial(keyStore, WechatConfigure.certPassword.toCharArray()) |
| | | .loadKeyMaterial(keyStore, mchId.toCharArray()) |
| | | .build(); |
| | | // Allow TLSv1 protocol only |
| | | SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( |
| | |
| | | null, |
| | | SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); |
| | | |
| | | |
| | | httpClient = HttpClients.custom() |
| | | |
| | | httpClient = HttpClients.custom() |
| | | .setSSLSocketFactory(sslsf) |
| | | .build(); |
| | | // httpClient = HttpClients.custom().build(); |
| | | // httpClient = HttpClients.custom().build(); |
| | | //根据默认超时限制初始化requestConfig |
| | | requestConfig = RequestConfig.custom().setSocketTimeout(socketTimeout).setConnectTimeout(connectTimeout).build(); |
| | | hasInit = true; |
| | |
| | | httpPost.setConfig(requestConfig); |
| | | |
| | | log.info("executing request" + httpPost.getRequestLine()); |
| | | |
| | | |
| | | try { |
| | | HttpResponse response = httpClient.execute(httpPost); |
| | | |
| | | HttpEntity entity = response.getEntity(); |
| | | |
| | | result = EntityUtils.toString(entity, "UTF-8"); |
| | | |
| | | |
| | | log.info("POST back date:" + httpPost.getRequestLine()); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } catch (ConnectionPoolTimeoutException e) { |
| | | // log.e("http get throw ConnectionPoolTimeoutException(wait time out)"); |
| | |
| | | // log.e("http get throw SocketTimeoutException"); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | e.printStackTrace(); |
| | | // log.e("http get throw Exception"); |
| | | |
| | | } finally { |
| | |
| | | * @param socketTimeout 连接时长,默认10秒 |
| | | */ |
| | | public void setSocketTimeout(int socketTimeout) { |
| | | this.socketTimeout = socketTimeout; |
| | | this.socketTimeout = socketTimeout; |
| | | resetRequestConfig(); |
| | | } |
| | | |
| | |
| | | * @param connectTimeout 传输时长,默认30秒 |
| | | */ |
| | | public void setConnectTimeout(int connectTimeout) { |
| | | this.connectTimeout = connectTimeout; |
| | | this.connectTimeout = connectTimeout; |
| | | resetRequestConfig(); |
| | | } |
| | | |
| | |
| | | * @param requestConfig 设置HttpsRequest的请求器配置 |
| | | */ |
| | | public void setRequestConfig(RequestConfig requestConfig) { |
| | | this.requestConfig = requestConfig; |
| | | this.requestConfig = requestConfig; |
| | | } |
| | | |
| | | |
| | | public String getMchId() { |
| | | return mchId; |
| | | } |
| | | |
| | | public void setMchId(String mchId) { |
| | | this.mchId = mchId; |
| | | } |
| | | |
| | | public String getCertLocalPath() { |
| | | return certLocalPath; |
| | | } |
| | | |
| | | public void setCertLocalPath(String certLocalPath) { |
| | | this.certLocalPath = certLocalPath; |
| | | } |
| | | } |
| | |
| | | * @return 签名 |
| | | * @throws IllegalAccessException |
| | | */ |
| | | public static String getSign(Object o) throws IllegalAccessException { |
| | | public static String getSign(Object o,String paySecret) throws IllegalAccessException { |
| | | ArrayList<String> list = new ArrayList<String>(); |
| | | Class<? extends Object> cls = o.getClass(); |
| | | Field[] fields = cls.getDeclaredFields(); |
| | |
| | | sb.append(arrayToSort[i]); |
| | | } |
| | | String result = sb.toString(); |
| | | result += "key=" + WechatConfigure.key; |
| | | result += "key=" +paySecret; |
| | | Util.log("Sign Before MD5:" + result); |
| | | result = MD5.MD5Encode(result).toUpperCase(); |
| | | Util.log("Sign Result:" + result); |
| | | return result; |
| | | } |
| | | |
| | | public static String getSign(Map<String, Object> map) { |
| | | public static String getSign(Map<String, Object> map,String paySecret) { |
| | | ArrayList<String> list = new ArrayList<String>(); |
| | | for (Map.Entry<String, Object> entry : map.entrySet()) { |
| | | if (entry.getValue() != "") { |
| | |
| | | sb.append(arrayToSort[i]); |
| | | } |
| | | String result = sb.toString(); |
| | | result += "key=" + WechatConfigure.key; |
| | | result += "key=" + paySecret; |
| | | Util.log("Sign Before MD5:" + result); |
| | | result = MD5.MD5Encode(result).toUpperCase(); |
| | | Util.log("Sign Result:" + result); |
| | |
| | | * @throws IOException |
| | | * @throws SAXException |
| | | */ |
| | | public static String getSignFromResponseString(String responseString) |
| | | public static String getSignFromResponseString(String responseString,String paySecret) |
| | | throws IOException, SAXException, ParserConfigurationException { |
| | | Map<String, Object> map = XMLParser.getMapFromXML(responseString); |
| | | // 清掉返回数据对象里面的Sign数据(不能把这个数据也加进去进行签名),然后用签名算法进行签名 |
| | | map.put("sign", ""); |
| | | // 将API返回的数据根据用签名算法进行计算新的签名,用来跟API返回的签名进行比较 |
| | | return Signature.getSign(map); |
| | | return Signature.getSign(map,paySecret); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws IOException |
| | | * @throws SAXException |
| | | */ |
| | | public static boolean checkIsSignValidFromResponseString(String responseString) |
| | | public static boolean checkIsSignValidFromResponseString(String responseString,String paySecret) |
| | | throws ParserConfigurationException, IOException, SAXException { |
| | | |
| | | Map<String, Object> map = XMLParser.getMapFromXML(responseString); |
| | |
| | | // 清掉返回数据对象里面的Sign数据(不能把这个数据也加进去进行签名),然后用签名算法进行签名 |
| | | map.put("sign", ""); |
| | | // 将API返回的数据根据用签名算法进行计算新的签名,用来跟API返回的签名进行比较 |
| | | String signForAPIResponse = Signature.getSign(map); |
| | | String signForAPIResponse = Signature.getSign(map,paySecret); |
| | | |
| | | if (!signForAPIResponse.equals(signFromAPIResponse)) { |
| | | // 签名验不过,表示这个API返回的数据有可能已经被篡改了 |
| | |
| | | return true; |
| | | } |
| | | |
| | | public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException { |
| | | System.out.println(checkIsSignValidFromResponseString("<xml><appid><![CDATA[wx13515a9204ea669d]]></appid><attach><![CDATA[35f7170585ad4f09b5109cc985b1eec0]]></attach><bank_type><![CDATA[CFT]]></bank_type><cash_fee><![CDATA[1]]></cash_fee><fee_type><![CDATA[CNY]]></fee_type><is_subscribe><![CDATA[N]]></is_subscribe><mch_id><![CDATA[1486409192]]></mch_id><nonce_str><![CDATA[elqhnr10vzaq0wgalf9njjyqwyd7gyr7]]></nonce_str><openid><![CDATA[o8x8E5lqmD9c5rdsjTQ9KWN4-H40]]></openid><out_trade_no><![CDATA[2018090610284198419]]></out_trade_no><result_code><![CDATA[SUCCESS]]></result_code><return_code><![CDATA[SUCCESS]]></return_code><sign><![CDATA[DD04172CDAA60F834163AF3F5B63BE3F]]></sign><time_end><![CDATA[20180906102853]]></time_end><total_fee>1</total_fee><trade_type><![CDATA[JSAPI]]></trade_type><transaction_id><![CDATA[4200000169201809067369627940]]></transaction_id></xml>")); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | |
| | | // 这个就是自己要保管好的私有Key了(切记只能放在自己的后台代码里,不能放在任何可能被看到源代码的客户端程序中) |
| | | // 每次自己Post数据给API的时候都要用这个key来对所有字段进行签名,生成的签名会放在Sign这个字段,API收到Post数据的时候也会用同样的签名算法对Post过来的数据进行签名和验证 |
| | | // 收到API的返回的时候也要用这个key来对返回的数据算下签名,跟API的Sign数据进行比较,如果值不一致,有可能数据被第三方给篡改 |
| | | public static final String PAY_NOTIFY_URL="https://xcxhive2.jyymatrix.cc/wxCommon/wxpayCallback"; |
| | | |
| | | // 交易类型 |
| | | public static final String TRADE_TYPE_JSAPI = "JSAPI"; |
| | | public static final String TRADE_TYPE_NATIVE = "NATIVE"; |
| | |
| | | public static final String SIGN_MD5 = "MD5"; |
| | | //域名 |
| | | |
| | | |
| | | // 微信支付秘钥 |
| | | public static String key = "3hbNHPOSXx85rC0QEqvGgIHu1wduT4Qc"; |
| | | |
| | | // 微信分配的公众号ID(开通公众号之后可以获取到) |
| | | public static String appID = "wx3836ab3c1490ff29"; |
| | | |
| | | |
| | | |
| | | // 微信支付分配的商户号ID(开通公众号的微信支付功能之后可以获取到) |
| | | public static String mchID = "1573208361"; |
| | | |
| | | |
| | | public static String web_appID = "1486409192"; |
| | | |
| | | // 受理模式下给子商户分配的子商户号 |
| | | public static String subMchID = ""; |
| | | |
| | | // HTTPS证书的本地路径 |
| | | public static String certLocalPath = "/home/cert/apiclient_cert.p12"; |
| | | |
| | | // HTTPS证书密码,默认密码等于商户号MCHID |
| | | public static String certPassword = "1573208361"; |
| | | |
| | | |
| | | // 是否使用异步线程的方式来上报API测速,默认为异步模式 |
| | | public static boolean useThreadToDoReport = true; |
| | |
| | | private String signType = ""; |
| | | private String paySign = ""; |
| | | |
| | | public BrandWCPayRequestData(String prepay_id){ |
| | | public BrandWCPayRequestData(String prepay_id,String appID,String paySecret){ |
| | | //默认必须设置 |
| | | setAppId(WechatConfigure.appID); |
| | | setAppId(appID); |
| | | //随机字符串,不长于32 位 |
| | | setNonceStr(RandomStringGenerator.getRandomStringByLength(32)); |
| | | setTimeStamp(Long.toString(System.currentTimeMillis() / 1000L)); |
| | | setPrepay_id("prepay_id="+prepay_id); |
| | | //根据API给的签名规则进行签名 【 必须要放在本方法的最后】 |
| | | setSignType(WechatConfigure.SIGN_MD5); |
| | | String sign = Signature.getSign(toMap()); |
| | | String sign = Signature.getSign(toMap(),paySecret); |
| | | setPaySign(sign);//把签名数据设置到Sign这个属性中 |
| | | } |
| | | |
| | |
| | | * @param bankTrueName 收款号姓名 |
| | | * @param bankCode 收款号开户行 |
| | | */ |
| | | public JsApiPayComReqData(String desc, String outTradeNo, int totalFee, String bankNo, String bankTrueName, String bankCode) { |
| | | public JsApiPayComReqData(String mchID,String paySecret ,String desc, String outTradeNo, int totalFee, String bankNo, String bankTrueName, String bankCode) { |
| | | //默认必须设置 |
| | | setMch_id(WechatConfigure.mchID); |
| | | setMch_id(mchID); |
| | | setDesc(desc); |
| | | setPartner_trade_no(outTradeNo); |
| | | setAmount(totalFee); |
| | | //随机字符串,不长于32 位 |
| | | setNonce_str(RandomStringGenerator.getRandomStringByLength(32)); |
| | | //根据API给的签名规则进行签名 【 必须要放在本方法的最后】 |
| | | String sign = Signature.getSign(toMap()); |
| | | String sign = Signature.getSign(toMap(),paySecret); |
| | | setSign(sign);//把签名数据设置到Sign这个属性中 |
| | | // setEnc_bank_no(); |
| | | // setEnc_true_name(); |
| | |
| | | /** |
| | | * 接收微信支付异步通知回调地址 |
| | | */ |
| | | private String notify_url = WechatConfigure.PAY_NOTIFY_URL; |
| | | private String trade_type = WechatConfigure.TRADE_TYPE_JSAPI; |
| | | private String notify_url ; |
| | | private String openid = ""; |
| | | private String limit_pay = ""; |
| | | private String spbill_create_ip = ""; |
| | |
| | | public JsApiPayReqData() { |
| | | } |
| | | |
| | | /** |
| | | /**appID 收款应用id |
| | | * mchID 商户号 |
| | | * @param authCode 这个是扫码终端设备从用户手机上扫取到的支付授权号,这个号是跟用户用来支付的银行卡绑定的,有效期是1分钟 |
| | | * @param body 要支付的商品的描述信息,用户会在支付成功页面里看到这个信息 |
| | | * @param attach 支付订单里面可以填的附加数据,API会将提交的这个附加数据原样返回 |
| | |
| | | * @param timeExpire 订单失效时间,格式同上 |
| | | * @param goodsTag 商品标记,微信平台配置的商品标记,用于优惠券或者满减使用 |
| | | */ |
| | | public JsApiPayReqData(String body,String outTradeNo,int totalFee,String spBillCreateIP,String openid,String attach){ |
| | | public JsApiPayReqData(String appID, String mchID,String paySecret,String notify_url, String body,String outTradeNo,int totalFee,String spBillCreateIP,String openid,String attach){ |
| | | //默认必须设置 |
| | | setAppid(WechatConfigure.appID); |
| | | setMch_id(WechatConfigure.mchID); |
| | | setAppid(appID); |
| | | setMch_id(mchID); |
| | | setNotify_url(notify_url); |
| | | setBody(body); |
| | | setOut_trade_no(outTradeNo); |
| | | setTotal_fee(totalFee); |
| | |
| | | setNonce_str(RandomStringGenerator.getRandomStringByLength(32)); |
| | | setOpenid(openid); |
| | | //根据API给的签名规则进行签名 【 必须要放在本方法的最后】 |
| | | String sign = Signature.getSign(toMap()); |
| | | String sign = Signature.getSign(toMap(),paySecret); |
| | | setSign(sign);//把签名数据设置到Sign这个属性中 |
| | | |
| | | } |
| | | |
| | | public JsApiPayReqData(String body,String outTradeNo,int totalFee,String spBillCreateIP,String attach){ |
| | | public JsApiPayReqData(String appID, String mchID,String paySecret,String notify_url,String body,String outTradeNo,int totalFee,String spBillCreateIP,String attach){ |
| | | //默认必须设置 |
| | | setAppid(WechatConfigure.web_appID); |
| | | setMch_id(WechatConfigure.mchID); |
| | | setAppid(appID); |
| | | setMch_id(mchID); |
| | | setBody(body); |
| | | setNotify_url(notify_url); |
| | | setOut_trade_no(outTradeNo); |
| | | setTotal_fee(totalFee); |
| | | setSpbill_create_ip(spBillCreateIP); |
| | |
| | | //随机字符串,不长于32 位 |
| | | setNonce_str(RandomStringGenerator.getRandomStringByLength(32)); |
| | | //根据API给的签名规则进行签名 【 必须要放在本方法的最后】 |
| | | String sign = Signature.getSign(toMap()); |
| | | String sign = Signature.getSign(toMap(),paySecret); |
| | | setSign(sign);//把签名数据设置到Sign这个属性中 |
| | | } |
| | | |
| | |
| | | //-------------------------------------------------------------------- |
| | | |
| | | //微信分配的公众号ID(开通公众号之后可以获取到) |
| | | setAppid(WechatConfigure.appID); |
| | | //setAppid(WechatConfigure.appID); |
| | | |
| | | //微信支付分配的商户号ID(开通公众号的微信支付功能之后可以获取到) |
| | | setMch_id(WechatConfigure.mchID); |
| | | // setMch_id(WechatConfigure.mchID); |
| | | |
| | | //transaction_id是微信系统为每一笔支付交易分配的订单号,通过这个订单号可以标识这笔交易,它由支付订单API支付成功时返回的数据里面获取到。 |
| | | setTransaction_id(transactionID); |
| | |
| | | setNonce_str(RandomStringGenerator.getRandomStringByLength(32)); |
| | | |
| | | //根据API给的签名规则进行签名 |
| | | String sign = Signature.getSign(toMap()); |
| | | //String sign = Signature.getSign(toMap()); |
| | | setSign(sign);//把签名数据设置到Sign这个属性中 |
| | | |
| | | |
| | |
| | | * @param opUserID 操作员帐号, 默认为商户号 |
| | | * @param refundFeeType 货币类型,符合ISO 4217标准的三位字母代码,默认为CNY(人民币) |
| | | */ |
| | | public RefundReqData(String outTradeNo,String outRefundNo,int totalFee,int refundFee,String opUserID){ |
| | | public RefundReqData(String mchID,String appID,String paySecret ,String outTradeNo,String outRefundNo,int totalFee,int refundFee,String opUserID){ |
| | | |
| | | //微信分配的公众号ID(开通公众号之后可以获取到) |
| | | setAppid(WechatConfigure.appID); |
| | | setAppid(mchID); |
| | | |
| | | //微信支付分配的商户号ID(开通公众号的微信支付功能之后可以获取到) |
| | | setMch_id(WechatConfigure.mchID); |
| | | setMch_id(appID); |
| | | |
| | | //transaction_id是微信系统为每一笔支付交易分配的订单号,通过这个订单号可以标识这笔交易,它由支付订单API支付成功时返回的数据里面获取到。 |
| | | //setTransaction_id(transactionID); |
| | |
| | | setNonce_str(RandomStringGenerator.getRandomStringByLength(32)); |
| | | |
| | | //根据API给的签名规则进行签名 |
| | | String sign = Signature.getSign(toMap()); |
| | | String sign = Signature.getSign(toMap(),paySecret); |
| | | setSign(sign);//把签名数据设置到Sign这个属性中 |
| | | |
| | | } |
| | |
| | | public void setServiceRequest(IServiceRequest request){ |
| | | serviceRequest = request; |
| | | } |
| | | |
| | | public IServiceRequest getServiceRequest() { |
| | | return serviceRequest; |
| | | } |
| | | } |
| | |
| | | package com.matrix.component.wechat.externalInterface.weixinUtil; |
| | | |
| | | import com.matrix.component.wechat.externalInterface.common.HttpsRequest2; |
| | | import com.matrix.core.exception.GlobleException; |
| | | import com.matrix.core.tools.LogUtil; |
| | | import com.matrix.core.tools.StringUtils; |
| | |
| | | import com.matrix.component.wechat.externalInterface.service.JsApiPayComService; |
| | | import com.matrix.component.wechat.externalInterface.service.RefundService; |
| | | import com.matrix.component.wechat.externalInterface.service.ScanPayQueryService; |
| | | import com.matrix.system.common.bean.BusParameterSettings; |
| | | import com.matrix.system.common.constance.AppConstance; |
| | | import com.matrix.system.common.dao.BusParameterSettingsDao; |
| | | import com.matrix.system.common.interceptor.HostInterceptor; |
| | | import com.matrix.system.shopXcx.api.tools.WxShopOrderUtil; |
| | | import org.apache.log4j.Logger; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | @Autowired |
| | | private WxShopOrderUtil wxShopOrderUtil; |
| | | |
| | | @Autowired |
| | | BusParameterSettingsDao busParameterSettingsDao; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 支付"175.9.82.254" |
| | |
| | | // 创建微信支付预付接口 |
| | | JsApiPayBusiness jsApiPayBusiness = new JsApiPayBusiness(); |
| | | String idAddr = getIpAddr(WebUtil.getRequest()); |
| | | JsApiPayReqData jsApiPayReqData = new JsApiPayReqData(desc, outTradeNo, price, idAddr, openId, attach); |
| | | |
| | | Long companyId=HostInterceptor.getCompanyId(); |
| | | |
| | | BusParameterSettings mchID = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_APPID, companyId); |
| | | BusParameterSettings paySecret = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_SECRET, companyId); |
| | | BusParameterSettings notifyUrl = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_NOTIFYURL, companyId); |
| | | |
| | | BusParameterSettings appId = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.MINIPROGRAM_APPID, companyId); |
| | | |
| | | JsApiPayReqData jsApiPayReqData = new JsApiPayReqData(appId.getParamValue(),mchID.getParamValue(), |
| | | paySecret.getParamValue(), |
| | | notifyUrl.getParamValue(), |
| | | desc, outTradeNo, price, idAddr, openId, attach); |
| | | |
| | | // 创建预付订单并返回请求结果 |
| | | JsApiPayResData result = jsApiPayBusiness.createPrapareOrder(jsApiPayReqData); |
| | | // 把预付订单的信息存放在request域中 |
| | |
| | | LogUtil.info("#---签名信息:return_msg = {}" , result.getReturn_msg()); |
| | | if (result.getReturn_code().equals("SUCCESS")) { |
| | | // 请求成功, 构建BrandWCPayRequest发起支付需要的参数 |
| | | BrandWCPayRequestData payData = new BrandWCPayRequestData(result.getPrepay_id()); |
| | | BrandWCPayRequestData payData = new BrandWCPayRequestData(result.getPrepay_id(),appId.getParamValue(),paySecret.getParamValue()); |
| | | WebUtil.getRequest().setAttribute("payData", payData); |
| | | return payData; |
| | | }else{ |
| | |
| | | * @param desc 描述 |
| | | * @param outTradeNo 提现申请编号 |
| | | * @param totalFee 提现金额(分) |
| | | * @param spBillCreateIP 调用接口的IP |
| | | * @param openid |
| | | * @return |
| | | */ |
| | |
| | | try { |
| | | JsApiPayBusiness jsApiPayBusiness = new JsApiPayBusiness(); |
| | | // TODO 企业付款 |
| | | JsApiPayComReqData jsApiPayComReqData=new JsApiPayComReqData("","",0,"","",""); |
| | | Long companyId=HostInterceptor.getCompanyId(); |
| | | BusParameterSettings mchID = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_APPID, companyId); |
| | | BusParameterSettings paySecret = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_SECRET, companyId); |
| | | |
| | | |
| | | JsApiPayComReqData jsApiPayComReqData=new JsApiPayComReqData(mchID.getParamValue(),paySecret.getParamValue(),"","",0,"","",""); |
| | | JsApiPayComService jsApiPayComService=new JsApiPayComService(); |
| | | result = jsApiPayBusiness.payComOrder(jsApiPayComService, jsApiPayComReqData); |
| | | LogUtil.info("#提现,企业付款到个人---result:{}",result); |
| | |
| | | int refundFee, String opUserID){ |
| | | LogUtil.info("#---outTradeNo:{}#---outRefundNo:{}#---totalFee:{}#---refundFee:{}", |
| | | outTradeNo,outRefundNo,totalFee,refundFee); |
| | | BusParameterSettings mchID = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_APPID, HostInterceptor.getCompanyId()); |
| | | if(opUserID==null){ |
| | | opUserID=WechatConfigure.mchID; |
| | | opUserID=mchID.getParamValue(); |
| | | } |
| | | RefundResData result=null; |
| | | boolean flag=false; |
| | | try { |
| | | JsApiPayBusiness jsApiPayBusiness = new JsApiPayBusiness(); |
| | | RefundReqData refundReqData=new RefundReqData(outTradeNo, outRefundNo, totalFee, refundFee,opUserID); |
| | | Long companyId=HostInterceptor.getCompanyId(); |
| | | BusParameterSettings paySecret = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_SECRET, companyId); |
| | | BusParameterSettings appId = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_APPID, companyId); |
| | | BusParameterSettings certLocalPath = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_CERTLOCAL_PATH, companyId); |
| | | |
| | | RefundReqData refundReqData=new RefundReqData(mchID.getParamValue(),appId.getParamValue(),paySecret.getParamValue(), outTradeNo, outRefundNo, totalFee, refundFee,opUserID); |
| | | RefundService refundService=new RefundService(); |
| | | HttpsRequest2 request2= (HttpsRequest2) refundService.getServiceRequest(); |
| | | request2.setCertLocalPath(certLocalPath.getParamValue()); |
| | | request2.setMchId(mchID.getParamValue()); |
| | | |
| | | result = jsApiPayBusiness.refundComOrder(refundService, refundReqData); |
| | | LogUtil.info("#退款,企业付款到个人---result:{}",result); |
| | | //如果返回余额不足时 |
| | |
| | | * @return |
| | | */ |
| | | public String getIpAddr(HttpServletRequest request) { |
| | | String ip = request.getHeader("x-forwarded-for"); |
| | | /* if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
| | | ip = request.getHeader("Proxy-Client-IP"); |
| | | } |
| | | if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
| | | ip = request.getHeader("WL-Proxy-Client-IP"); |
| | | String ip = request.getHeader("x-forwarded-for"); |
| | | /* if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
| | | ip = request.getHeader("Proxy-Client-IP"); |
| | | } |
| | | if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
| | | ip = request.getHeader("WL-Proxy-Client-IP"); |
| | | } */ |
| | | if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
| | | ip = request.getRemoteAddr(); |
| | |
| | | import com.matrix.component.rabbitmq.RabiitMqTemplate; |
| | | import com.matrix.component.rabbitmq.RabiitMqTemplateFactory; |
| | | import com.matrix.system.shopXcx.mqTask.*; |
| | | import com.matrix.system.wechart.templateMsg.Task.UniformMsgSentTask; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | |
| | | return new TemplateMsgTask(); |
| | | } |
| | | |
| | | @Bean |
| | | UniformMsgSentTask UniformMsgSentTask(){ |
| | | return new UniformMsgSentTask(); |
| | | } |
| | | |
| | | @Bean |
| | | OrderOutSotoreTask OrderOutSotoreTask(){ |
| | | return new OrderOutSotoreTask(); |
| | |
| | | |
| | | //注册RabbitMq任务 |
| | | taskList.add(new MqTask(MQ_EXCHANGE_A + evn, MQTaskRouting.CREATE_VIP + evn, MQTaskRouting.CREATE_VIP + evn, VipCreateTask())); |
| | | taskList.add(new MqTask(MQ_EXCHANGE_A + "cf", MQTaskRouting.CREATE_VIP + evn, MQTaskRouting.CREATE_VIP + evn, null)); |
| | | taskList.add(new MqTask(MQ_EXCHANGE_A + evn, MQTaskRouting.CREATE_ORDER + evn,MQTaskRouting.CREATE_ORDER + evn,OrderrCreateTask())); |
| | | taskList.add(new MqTask(MQ_EXCHANGE_A + evn, MQTaskRouting.SEND_TEMPLATE_MSG + evn,MQTaskRouting.SEND_TEMPLATE_MSG + evn, TemplateMsgTask())); |
| | | taskList.add(new MqTask(MQ_EXCHANGE_A + evn, MQTaskRouting.ORDER_OUT_SOTORE + evn,MQTaskRouting.ORDER_OUT_SOTORE + evn, OrderOutSotoreTask())); |
| | | taskList.add(new MqTask(MQ_EXCHANGE_A + evn, MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG + evn,MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG + evn, UniformMsgSentTask())); |
| | | |
| | | rabiitMqTemplate.binding(taskList); |
| | | |
| | |
| | | throw new IllegalArgumentException(">>>>>>>>>>> xxl-glue, loadNewInstance error, instance is null"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据字符串获取几个java实例 |
| | | * @param codeSource |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public Object loadInstance(String codeSource) throws Exception{ |
| | | if (codeSource!=null && codeSource.trim().length()>0) { |
| | | Class<?> clazz = groovyClassLoader.parseClass(codeSource); |
| | | if (clazz != null) { |
| | | Object instance = clazz.newInstance(); |
| | | if (instance!=null) { |
| | | this.injectService(instance); |
| | | return instance; |
| | | } |
| | | } |
| | | } |
| | | throw new IllegalArgumentException(">>>>>>>>>>> xxl-glue, loadNewInstance error, instance is null"); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | if (!vipInfo.getPassWord().equals(serviceOrderDto.getPassword())) { |
| | | return AjaxResult.buildSuccessInstance("资金密码错误"); |
| | | return AjaxResult.buildFailInstance("资金密码错误"); |
| | | } |
| | | |
| | | SysProjServices sysProjServices = new SysProjServices(); |
| | |
| | | public static final String QSFY = "QSFY"; |
| | | |
| | | |
| | | /** |
| | | * 小程序APPID |
| | | */ |
| | | public static final String MINIPROGRAM_APPID = "miniprogramAppid"; |
| | | /** |
| | | * 小程序Secret |
| | | */ |
| | | public static final String MINIPROGRAM_SECRET = "miniprogramSecret"; |
| | | /** |
| | | * 公众号APPID |
| | | */ |
| | | public static final String GZH_APPID = "gzhAppId"; |
| | | |
| | | /** |
| | | * 微信商户号 |
| | | */ |
| | | public static final String WECHARPAY_APPID = "wecharPayAppid"; |
| | | /** |
| | | * 支付秘钥 |
| | | */ |
| | | public static final String WECHARPAY_SECRET = "wecharPaySecret"; |
| | | |
| | | /** |
| | | * 支付通知地址 |
| | | */ |
| | | public static final String WECHARPAY_NOTIFYURL = "wecharPaynotifyUrl"; |
| | | /** |
| | | * 支付证书地址 |
| | | */ |
| | | public static final String WECHARPAY_CERTLOCAL_PATH = "certLocalPath"; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | package com.matrix.system.hive.service.imp; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.matrix.component.rabbitmq.RabiitMqTemplate; |
| | | import com.matrix.core.constance.MatrixConstance; |
| | | import com.matrix.core.exception.GlobleException; |
| | | import com.matrix.core.pojo.PaginationVO; |
| | |
| | | import com.matrix.system.hive.plugin.util.MoneyUtil; |
| | | import com.matrix.system.hive.pojo.MyBeauticianCount; |
| | | import com.matrix.system.hive.service.*; |
| | | import com.matrix.system.shopXcx.mqTask.MQTaskRouting; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | WarehouseDao warehouseDao; |
| | | @Resource |
| | | private ShoppingGoodsService shoppingGoodsService; |
| | | |
| | | @Autowired |
| | | private RabiitMqTemplate rabiitMqTemplate; |
| | | |
| | | @Value("${evn}") |
| | | private String evn; |
| | | |
| | | |
| | | /** |
| | | * 新增服务单 jyy |
| | |
| | | if (!projServices.getState().equals(Dictionary.SERVICE_STATU_FWWC)) { |
| | | throw new GlobleException("该服务单状态为" + projServices.getState() + ",不可以进行当前操作!"); |
| | | } else { |
| | | |
| | | projServices.setState(Dictionary.SERVICE_STATU_FFJS); |
| | | projServices.setConsumeTime(new Date()); |
| | | return sysProjServicesDao.update(projServices); |
| | | int result=sysProjServicesDao.update(projServices); |
| | | //发送微信公众号提醒 |
| | | JSONObject param=new JSONObject(); |
| | | param.put("companyId",projServices.getCompanyId()); |
| | | param.put("serviceId",projServices.getId()); |
| | | rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG+evn,param.toJSONString()); |
| | | return result; |
| | | } |
| | | } |
| | | |
| | |
| | | vipInfoDetailVo.setBirthday(sysVipInfo.getBirthday1()); |
| | | vipInfoDetailVo.setPassword(sysVipInfo.getPassWord()); |
| | | vipInfoDetailVo.setPhoto(sysVipInfo.getPhoto()); |
| | | vipInfoDetailVo.setVipNo(sysVipInfo.getVipNo()); |
| | | |
| | | List<SysVipLabel> labels = sysVipLabelDao.selectByVipId(sysVipInfo.getId()); |
| | | vipInfoDetailVo.setLabels(labels); |
| | |
| | | int reMoney = b1.multiply(bb).intValue(); |
| | | LogUtil.info("退款退款金额{}", reMoney); |
| | | |
| | | //Double refundMoney = 0.1 * 100; |
| | | //用户ID |
| | | String userId = WechatConfigure.mchID; |
| | | |
| | | |
| | | if (isDebug) { |
| | | boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, 1, 1, userId); |
| | | boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, 1, 1, null); |
| | | flag = b; |
| | | } else { |
| | | LogUtil.info("开始调用退款接口。。。退款编号为{}", refundNo); |
| | | boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, orMoney, reMoney, userId); |
| | | boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, orMoney, reMoney, null); |
| | | flag = b; |
| | | } |
| | | |
| | |
| | | import com.matrix.core.pojo.AjaxResult; |
| | | import com.matrix.core.tools.StringUtils; |
| | | import com.matrix.system.common.constance.AppConstance; |
| | | import com.matrix.system.common.interceptor.HostInterceptor; |
| | | import com.matrix.system.constance.Dictionary; |
| | | import com.matrix.system.hive.bean.ShoppingGoods; |
| | | import com.matrix.system.hive.dao.ShoppingGoodsDao; |
| | |
| | | import com.matrix.component.wechat.externalInterface.common.Signature; |
| | | import com.matrix.component.wechat.externalInterface.common.Util; |
| | | import com.matrix.component.wechat.externalInterface.protocol.queryProtocol.NotifyData; |
| | | import com.matrix.system.common.bean.BusParameterSettings; |
| | | import com.matrix.system.common.constance.AppConstance; |
| | | import com.matrix.system.common.dao.BusParameterSettingsDao; |
| | | import com.matrix.system.common.interceptor.HostInterceptor; |
| | | import com.matrix.system.hive.bean.SysVipInfo; |
| | | import com.matrix.system.hive.dao.SysVipInfoDao; |
| | | import com.matrix.system.shopXcx.bean.ShopActivitiesGroupJoin; |
| | |
| | | @Autowired |
| | | private SysVipInfoDao sysVipInfoDao; |
| | | |
| | | @Autowired |
| | | BusParameterSettingsDao busParameterSettingsDao; |
| | | |
| | | |
| | | |
| | | @Value("${evn}") |
| | | private String evn; |
| | | /** |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @RequestMapping(value = "/wxpayCallback") |
| | | @RequestMapping(value = "/wxapi/wxpayCallback") |
| | | public void payCallBack(HttpServletResponse response, HttpServletRequest request) throws IOException { |
| | | LogUtil.info("微信支付回调start...."); |
| | | |
| | |
| | | // 返回状态码 SUCCESS/FAIL |
| | | if (AppConstance.CODE_SUCCESS.equals(data.getReturn_code())) { |
| | | // 校验签名 |
| | | if (Signature.checkIsSignValidFromResponseString(notityXml.toString())) { |
| | | BusParameterSettings paySecret = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_SECRET, HostInterceptor.getCompanyId()); |
| | | if (Signature.checkIsSignValidFromResponseString(notityXml.toString(),paySecret.getParamValue())) { |
| | | // 校验业务结果 |
| | | if (AppConstance.CODE_SUCCESS.equals(data.getResult_code())) { |
| | | // 返回SUCCESS报文 |
| | |
| | | |
| | | //Double refundMoney = 0.1 * 100; |
| | | //用户ID |
| | | String userId = WechatConfigure.mchID; |
| | | |
| | | if (isDebug) { |
| | | boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, 1, 1, userId); |
| | | boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, 1, 1, null); |
| | | flag = b; |
| | | } else { |
| | | LogUtil.info("开始调用退款接口。。。退款编号为", refundNo); |
| | | boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, orMoney, reMoney, userId); |
| | | boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, orMoney, reMoney, null); |
| | | flag = b; |
| | | } |
| | | |
| | |
| | | */ |
| | | private Integer status; |
| | | |
| | | /** |
| | | * 模板类型 1,公众号,2,小程序 |
| | | */ |
| | | private Integer tempType; |
| | | |
| | | |
| | | /** |
| | | * 取数模板类 |
| | | */ |
| | | private String templateClass; |
| | | |
| | | /** |
| | | * 模板备注 |
| | |
| | | } |
| | | } |
| | | |
| | | public void buildDicMap(Object value) { |
| | | if (value != null) { |
| | | STATUS[] statusArray = STATUS.values(); |
| | | for (STATUS s : statusArray) { |
| | | if (s.getCode().equals(value)) { |
| | | getDicMap().put("status", s.getName()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | public enum TempType { |
| | | |
| | | MP("公众号", 1), |
| | | |
| | | APP("小程序", 2); |
| | | |
| | | private TempType(String name, int code) { |
| | | this.name = name; |
| | | this.code = code; |
| | | } |
| | | |
| | | private String name; |
| | | private Integer code; |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public Integer getCode() { |
| | | return code; |
| | | } |
| | | |
| | | public void setCode(Integer code) { |
| | | this.code = code; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | public void setStatus(Integer status) { |
| | | buildDicMap(status); |
| | | |
| | | buildDicMap("status"); |
| | | |
| | | if (status != null) { |
| | | STATUS[] statusArray = STATUS.values(); |
| | | for (STATUS s : statusArray) { |
| | | if (s.getCode().equals(status)) { |
| | | getDicMap().put("status", s.getName()); |
| | | } |
| | | } |
| | | } |
| | | this.status = status; |
| | | } |
| | | |
| | | public String getTemplateClass() { |
| | | return templateClass; |
| | | } |
| | | |
| | | public void setTemplateClass(String templateClass) { |
| | | |
| | | this.templateClass = templateClass; |
| | | } |
| | | |
| | | public Integer getTempType() { |
| | | |
| | | return tempType; |
| | | } |
| | | |
| | | public void setTempType(Integer tempType) { |
| | | if (tempType != null) { |
| | | TempType[] statusArray = TempType.values(); |
| | | for (TempType s : statusArray) { |
| | | if (s.getCode().equals(tempType)) { |
| | | getDicMap().put("tempType", s.getName()); |
| | | } |
| | | } |
| | | } |
| | | this.tempType = tempType; |
| | | } |
| | | |
| | | public Integer getId() { |
| | | return id; |
| | |
| | | |
| | | public int deleteById(Integer id); |
| | | |
| | | public ShopWxtemplateMsg selectByCode(Integer code); |
| | | public ShopWxtemplateMsg selectByCode(@Param("code") Integer code, @Param("companyId") Long companyId); |
| | | |
| | | public int deleteByModel(@Param("record") ShopWxtemplateMsg shopWxtemplateMsg); |
| | | |
| | |
| | | * 发送微信消息 |
| | | */ |
| | | String SEND_TEMPLATE_MSG = "SEND_TEMPLATE_MSG"; |
| | | |
| | | /** |
| | | * 发送小程序统一模板消息 |
| | | */ |
| | | String SEND_UNIFORM_TEMPLATE_MSG = "SEND_UNIFORM_TEMPLATE_MSG"; |
| | | |
| | | /** |
| | | * 订单出库 |
| | | */ |
| | |
| | | } else { |
| | | SysVipInfo vipInfo = new SysVipInfo(); |
| | | //在备注记下微商城的用户id |
| | | vipInfo.setRemark(userInfo.getOpenId()); |
| | | vipInfo.setOpenId(userInfo.getOpenId()); |
| | | vipInfo.setAddr(userInfo.getProvince() + " " + userInfo.getCity()); |
| | | vipInfo.setPhone(userInfo.getPhoneNumber()); |
| | | if (userInfo.getGender() != null) { |
| | |
| | | SysShopInfo shopInfo = shopInfoDao.selectById(onlinebooking.getShopId()); |
| | | |
| | | //获取模板id |
| | | ShopWxtemplateMsg wxtemplateMsg = wxtemplateMsgDao.selectByCode(TemplateMsgType.APPOINTMENT_SUCCESS.getCode()); |
| | | ShopWxtemplateMsg wxtemplateMsg = wxtemplateMsgDao.selectByCode(TemplateMsgType.APPOINTMENT_SUCCESS.getCode(), 17L); |
| | | |
| | | |
| | | String page = "pages/yuyue/yyInfo?id=" + orderId + "&model=1"; |
New file |
| | |
| | | package com.matrix.system.wechart.templateMsg; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.matrix.component.tools.HttpClientUtil; |
| | | import com.matrix.core.pojo.AjaxResult; |
| | | import com.matrix.system.hive.plugin.util.HttpUtils; |
| | | import com.matrix.system.shopXcx.api.WeChatGzhApiTools; |
| | | import com.matrix.system.wechart.templateMsg.Task.UniformMsgSentTask; |
| | | import com.rabbitmq.client.Delivery; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | @Controller |
| | | @RequestMapping(value = "test3") |
| | | public class MsgDemo3 { |
| | | |
| | | |
| | | @Autowired |
| | | UniformMsgSentTask uniformMsgSentTask; |
| | | |
| | | @RequestMapping("/template") |
| | | @ResponseBody |
| | | public AjaxResult template() throws IOException { |
| | | |
| | | uniformMsgSentTask.handle(null,null); |
| | | return AjaxResult.buildSuccessInstance("1"); |
| | | |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.matrix.system.wechart.templateMsg.Task; |
| | | |
| | | import com.matrix.system.wechart.templateMsg.UniformMsgPojo; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 动态构建消息主体内容 |
| | | * @author jyy |
| | | * |
| | | */ |
| | | public interface TemplateMessageBulder { |
| | | /** |
| | | * * 返回的map中 如果包含错误消息用error属性来表示 |
| | | * @param param |
| | | * @return |
| | | */ |
| | | Map buildMsg(Map param); |
| | | } |
New file |
| | |
| | | package com.matrix.system.wechart.templateMsg.Task; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.matrix.biz.bean.BizUser; |
| | | import com.matrix.biz.service.BizUserService; |
| | | import com.matrix.component.tools.HttpClientUtil; |
| | | import com.matrix.core.pojo.AjaxResult; |
| | | import com.matrix.core.tools.LogUtil; |
| | | import com.matrix.core.tools.rr.GlueFactory; |
| | | import com.matrix.system.common.bean.BusParameterSettings; |
| | | import com.matrix.system.common.constance.AppConstance; |
| | | import com.matrix.system.common.dao.BusParameterSettingsDao; |
| | | import com.matrix.system.constance.Dictionary; |
| | | import com.matrix.system.hive.bean.SysProjServices; |
| | | import com.matrix.system.hive.bean.SysVipInfo; |
| | | import com.matrix.system.hive.dao.SysProjServicesDao; |
| | | import com.matrix.system.hive.dao.SysShopInfoDao; |
| | | import com.matrix.system.hive.dao.SysVipInfoDao; |
| | | import com.matrix.system.shopXcx.api.WeChatGzhApiTools; |
| | | import com.matrix.system.shopXcx.bean.ShopWxtemplateMsg; |
| | | import com.matrix.system.shopXcx.dao.ShopWxtemplateMsgDao; |
| | | import com.matrix.system.wechart.templateMsg.GzhTemplateMessagePojo; |
| | | import com.matrix.system.wechart.templateMsg.TemplateNameConstance; |
| | | import com.matrix.system.wechart.templateMsg.UniformMsgPojo; |
| | | import com.rabbitmq.client.DeliverCallback; |
| | | import com.rabbitmq.client.Delivery; |
| | | import org.apache.commons.collections.map.HashedMap; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 小程序统一消息模板消息发送提醒 |
| | | * @author jyy |
| | | */ |
| | | @Component |
| | | public class UniformMsgSentTask implements DeliverCallback { |
| | | |
| | | @Autowired |
| | | private ShopWxtemplateMsgDao shopWxtemplateMsgDao; |
| | | |
| | | @Autowired |
| | | private BusParameterSettingsDao busParameterSettingsDao; |
| | | |
| | | /** |
| | | * 发送模板消息需要传JSONO字符串作为格式 |
| | | * 例如:{"companyId":17} |
| | | * companyId 是必须属性 |
| | | * @param consumerTag |
| | | * @param message |
| | | * @throws IOException |
| | | */ |
| | | @Override |
| | | public void handle(String consumerTag, Delivery message) throws IOException { |
| | | try { |
| | | |
| | | |
| | | String messages = new String(message.getBody(), "UTF-8"); |
| | | JSONObject messageJsonParam=JSONObject.parseObject(messages); |
| | | |
| | | if(!messageJsonParam.containsKey("companyId")){ |
| | | LogUtil.error("小程序消息推送参数格式异常发送模板消息需要传JSONO字符串作为格式 例如:{\"companyId\":17} companyId 是必须属性"); |
| | | return; |
| | | } |
| | | |
| | | Long companyId = Long.parseLong( messageJsonParam.get("companyId").toString()); |
| | | |
| | | //获取公司微信配置参数 |
| | | BusParameterSettings xcxAppId = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.MINIPROGRAM_APPID, companyId); |
| | | BusParameterSettings xcxSecret = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.MINIPROGRAM_SECRET, companyId); |
| | | BusParameterSettings gzhAppid = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.GZH_APPID, companyId); |
| | | //获取消息模板 |
| | | ShopWxtemplateMsg template = shopWxtemplateMsgDao.selectByCode(TemplateNameConstance.GZH_YYTX,companyId); |
| | | //校验参数 |
| | | if(xcxAppId==null||xcxSecret==null||gzhAppid==null||template==null){ |
| | | LogUtil.error("小程序消息推送配置缺失xcxAppId="+xcxAppId+";xcxSecret="+xcxSecret+";gzhAppid="+gzhAppid+";template="+template); |
| | | return; |
| | | } |
| | | |
| | | //获取模板动态构建类 |
| | | TemplateMessageBulder templateMessageBulder = (TemplateMessageBulder) GlueFactory.getInstance().loadInstance(template.getTemplateClass()); |
| | | //为模板动态类装备必要的参数 |
| | | Map<String, Object> bulderParam = new HashedMap(); |
| | | bulderParam.put("gzhAppid", gzhAppid.getParamValue()); |
| | | bulderParam.put("template_id", template.getUuid()); |
| | | bulderParam.put("messageJsonParam", messageJsonParam); |
| | | |
| | | |
| | | //调用模板计算出消息体 |
| | | Map msgResult = templateMessageBulder.buildMsg(bulderParam); |
| | | |
| | | if(msgResult.containsKey("error")){ |
| | | //错误消息处理 |
| | | LogUtil.error("模板消息发送失败:"+msgResult.get("error")); |
| | | return; |
| | | }else{ |
| | | //正常返回消息 |
| | | List msgList = (List) msgResult.get("msgList"); |
| | | //获取acceToken |
| | | String ACCESS_TOKEN = WeChatGzhApiTools.getAccessToken(xcxAppId.getParamValue(), xcxSecret.getParamValue()); |
| | | String url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=ACCESS_TOKEN".replaceAll("ACCESS_TOKEN", ACCESS_TOKEN); |
| | | for (Object msg : msgList) { |
| | | UniformMsgPojo uniformMsgPojo = (UniformMsgPojo) msg; |
| | | //推送消息到微信 |
| | | JSONObject result = HttpClientUtil.sendPostWithJson(url, JSONObject.toJSON(uniformMsgPojo).toString()); |
| | | //微信返回值 |
| | | LogUtil.debug("微信小程序模板消息推送结果:" + result.toString()); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | LogUtil.error("消费者执行异常", e); |
| | | } |
| | | |
| | | } |
| | | } |
New file |
| | |
| | | package com.matrix.system.wechart.templateMsg.Task.messageBulderDemo; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.matrix.biz.bean.BizUser; |
| | | import com.matrix.biz.dao.BizUserDao; |
| | | import com.matrix.core.tools.DateUtil; |
| | | import com.matrix.core.tools.StringUtils; |
| | | import com.matrix.system.hive.bean.SysBeauticianState; |
| | | import com.matrix.system.hive.bean.SysProjServices; |
| | | import com.matrix.system.hive.bean.SysVipInfo; |
| | | import com.matrix.system.hive.dao.SysBeauticianStateDao; |
| | | import com.matrix.system.hive.dao.SysProjServicesDao; |
| | | import com.matrix.system.hive.dao.SysVipInfoDao; |
| | | import com.matrix.system.wechart.templateMsg.GzhTemplateMessagePojo; |
| | | import com.matrix.system.wechart.templateMsg.Task.TemplateMessageBulder; |
| | | import com.matrix.system.wechart.templateMsg.UniformMsgPojo; |
| | | import io.swagger.models.auth.In; |
| | | import org.apache.commons.collections.map.HashedMap; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 某个公司客户的定制消息模板 |
| | | */ |
| | | @Component |
| | | public class DefaultTemplateMessageBulder implements TemplateMessageBulder { |
| | | |
| | | @Autowired |
| | | SysProjServicesDao projServicesDao; |
| | | |
| | | @Autowired |
| | | SysVipInfoDao vipInfoDao; |
| | | |
| | | @Autowired |
| | | private SysBeauticianStateDao beauticianStateDao; |
| | | |
| | | |
| | | |
| | | @Override |
| | | public Map buildMsg(Map param) { |
| | | |
| | | //返回参数 |
| | | Map builParam=new HashedMap(); |
| | | |
| | | |
| | | //获取基础公共参数 |
| | | String gzhAppid= (String) param.get("gzhAppid"); |
| | | String template_id= (String) param.get("template_id"); |
| | | //触发点传送的json参数 |
| | | JSONObject messageJsonParam= (JSONObject) param.get("messageJsonParam"); |
| | | |
| | | Long serviceId= (Long) messageJsonParam.get("serviceId"); |
| | | |
| | | |
| | | //构建消息主体 |
| | | SysProjServices sysProjServices = projServicesDao.selectById(serviceId); |
| | | |
| | | |
| | | //补充服务单扩展信息=============== |
| | | List<SysBeauticianState> beauticianStateList = beauticianStateDao.selectBySerIds(sysProjServices.getId()); |
| | | |
| | | SysVipInfo vipInfo=vipInfoDao.selectById(sysProjServices.getVipId()); |
| | | String touser= vipInfo.getOpenId(); |
| | | if(StringUtils.isBlank(touser)){ |
| | | builParam.put("error","未获取到"+vipInfo.getVipName()+"用户小程序openid"); |
| | | return builParam; |
| | | } |
| | | |
| | | String time= DateUtil.dateFormatStr(sysProjServices.getConsumeTime(),DateUtil.DATE_FORMAT_MM); |
| | | List msgList=new ArrayList(); |
| | | //如果一个项目存在多个护理项目则发送多次消息 |
| | | for (SysBeauticianState beauticianState:beauticianStateList){ |
| | | UniformMsgPojo uniformMsgPojo=new UniformMsgPojo(); |
| | | GzhTemplateMessagePojo messagePojo=new GzhTemplateMessagePojo(); |
| | | uniformMsgPojo.setTouser(touser); |
| | | messagePojo.setTemplate_id(template_id); |
| | | messagePojo.setAppid(gzhAppid); |
| | | |
| | | |
| | | //个性参数设置 |
| | | Integer suplerTimes= beauticianState.getProjUse().getSurplusCount(); |
| | | messagePojo.setFirst("尊敬的:"+vipInfo.getVipName(),"#453454"); |
| | | messagePojo.setKeyWord(beauticianState.getProjInfo().getName(),"#453454"); |
| | | messagePojo.setKeyWord(time,"#453454"); |
| | | messagePojo.setRemark("您的护理项目剩余"+suplerTimes+"次。","#453454"); |
| | | uniformMsgPojo.setMp_template_msg(messagePojo); |
| | | |
| | | |
| | | msgList.add(uniformMsgPojo); |
| | | } |
| | | |
| | | builParam.put("msgList",msgList); |
| | | return builParam; |
| | | } |
| | | } |
New file |
| | |
| | | package com.matrix.system.wechart.templateMsg; |
| | | |
| | | /** |
| | | * 模板code定义常量 |
| | | * @author jyy |
| | | */ |
| | | public interface TemplateNameConstance { |
| | | |
| | | /** |
| | | * 公众号预约提醒 |
| | | */ |
| | | Integer GZH_YYTX=10000; |
| | | |
| | | |
| | | } |
| | |
| | | evn=dev |
| | | evn=devbb |
| | | server.port=8080 |
| | | |
| | | |
New file |
| | |
| | | ALTER TABLE `shop_wxtemplate_msg` |
| | | ADD COLUMN `temp_type` int(2) NULL COMMENT ' 模板类型 1,公众号,2,小程序' AFTER `code`, |
| | | ADD COLUMN `template_class` longtext NULL COMMENT '取数模板类' AFTER `temp_type`; |
| | | |
| | | |
| | |
| | | |
| | | #hive仓库地址 |
| | | hive.service=http://erp.hive.jyymatrix.cc/meidu-crm/ |
| | | |
| | | gzh_appid=wx57e6335559bdbda6 |
| | | gzh_secret=ecb408af170e3890e6544290cad33760 |
| | |
| | | evn=dev |
| | | evn=tyytest |
| | | server.port=8080 |
| | | |
| | | |
| | | #线上测试环境 |
| | | |
| | | spring.datasource.username=chuhuan |
| | | spring.datasource.password=chuhuan |
| | | spring.datasource.url=jdbc:mysql://119.3.52.84:3306/hive_plus_test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&transformedBitIsBoolean=true&serverTimezone=GMT%2B8 |
| | | spring.datasource.username=ct_test |
| | | spring.datasource.password=123456 |
| | | spring.datasource.url=jdbc:mysql://120.27.238.55:3306/hive_test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&transformedBitIsBoolean=true&serverTimezone=GMT%2B8 |
| | | |
| | | |
| | | |
| | | |
| | |
| | | #是否启用debug模式 |
| | | debug=true |
| | | debug=false |
| | | # 日志文件保存地址 |
| | | log_path=/mnt/hive/log-test |
| | | |
| | |
| | | <result property="remark" column="remark" /> |
| | | <result property="companyId" column="company_id" /> |
| | | <result property="code" column="code" /> |
| | | <result property="tempType" column="temp_type" /> |
| | | <result property="templateClass" column="template_class" /> |
| | | </resultMap> |
| | | |
| | | |
| | |
| | | <result property="remark" column="remark" /> |
| | | <result property="companyId" column="company_id" /> |
| | | <result property="code" column="code" /> |
| | | <result property="tempType" column="temp_type" /> |
| | | <result property="templateClass" column="template_class" /> |
| | | </resultMap> |
| | | |
| | | <!-- 字段sql --> |
| | |
| | | status, |
| | | remark, |
| | | company_id, |
| | | code |
| | | code, |
| | | temp_type, |
| | | template_class |
| | | </sql> |
| | | |
| | | <!-- 属性sql --> |
| | |
| | | #{item.status}, |
| | | #{item.remark}, |
| | | #{item.companyId}, |
| | | #{item.code} |
| | | #{item.code}, |
| | | #{item.tempType}, |
| | | #{item.templateClass} |
| | | </sql> |
| | | |
| | | <!-- where sql --> |
| | | <sql id="where_sql"> |
| | | |
| | |
| | | <if test="(record.companyId!=null and record.companyId!='') or (record.companyId!='' and record.companyId==0) "> |
| | | and company_id = #{record.companyId} |
| | | </if> |
| | | |
| | | <if test="(record.tempType!=null and record.tempType!='') or (record.tempType!='' and record.tempType==0) "> |
| | | and tempType = #{record.tempType} |
| | | </if> |
| | | |
| | | |
| | | </if> |
| | | |
| | | </sql> |
| | |
| | | <if test="_parameter.containsKey('code')"> |
| | | code = #{code}, |
| | | </if> |
| | | <if test="_parameter.containsKey('temp_type')"> |
| | | temp_type = #{tempType}, |
| | | </if> |
| | | |
| | | </set> |
| | | WHERE id=#{id} |
| | | </update> |
| | |
| | | <if test="record.code != null and record.code != '' "> |
| | | code = #{record.code}, |
| | | </if> |
| | | |
| | | <if test="record.tempType != null and record.tempType != '' "> |
| | | temp_type = #{record.tempType}, |
| | | </if> |
| | | |
| | | </set> |
| | | WHERE id=#{record.id} |
| | | </update> |
| | |
| | | select |
| | | <include refid="columns" ></include> |
| | | from shop_wxtemplate_msg |
| | | where code=#{code} |
| | | where code=#{code} and company_id=#{companyId} |
| | | </select> |
| | | |
| | | |
| | |
| | | <th data-field="name">名称</th> |
| | | <th data-field="uuid">模板ID</th> |
| | | <th data-field="dicMap.status">是否启用</th> |
| | | <th data-field="dicMap.tempType">模板类型</th> |
| | | <th data-field="remark">备注</th> |
| | | </tr> |
| | | </thead> |