diff --git a/hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java b/hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java index 633c89e5..b8329ae3 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java @@ -6,9 +6,12 @@ import com.hai.common.pay.util.IOUtil; import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.utils.HttpsUtils; +import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.WxUtils; +import com.hai.model.ResponseData; import com.hai.model.WxSharingOrderRequestModel; import com.hai.model.WxSharingReceiversVO; +import com.hai.service.TelApiService; import com.hai.service.pay.NotifyService; import com.hai.service.pay.PayRecordService; import io.swagger.annotations.Api; @@ -19,6 +22,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @@ -42,6 +46,9 @@ public class WechatPayController { @Resource private WechatPayUtil wechatPayUtil; + @Resource + private TelApiService telApiService; + @RequestMapping(value = "/notify", method = RequestMethod.POST) @ApiOperation(value = "微信支付 -> 异步回调") public void wechatNotify(HttpServletRequest request, HttpServletResponse response) { @@ -180,7 +187,7 @@ public class WechatPayController { String url = "https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver"; String xm = WxUtils.mapToXml(map); - String rest = HttpsUtils.postData(url, xm); + String rest = String.valueOf(HttpsUtils.postData(url, xm)); System.out.println(rest); log.info("微信支付 -> 添加分账接收方:处理开始"); @@ -189,4 +196,16 @@ public class WechatPayController { } } + @RequestMapping(value = "/telApi", method = RequestMethod.GET) + @ApiOperation(value = "电话查询") + public ResponseData addLedgerReceiver(@RequestParam(value = "tel", required = true) String tel) { + try { + JSONObject jsonObject = telApiService.outApiTel(tel); + return ResponseMsgUtil.success(jsonObject); + } catch (Exception e) { + log.error("WechatPayController --> wechatNotify() error!", e); + return ResponseMsgUtil.exception(e); + } + } + } diff --git a/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java b/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java index 4be9e855..179ba971 100644 --- a/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java +++ b/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java @@ -3,7 +3,6 @@ package com.hai.common.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.hai.common.pay.util.IOUtil; import org.apache.commons.io.IOUtils; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -122,6 +121,47 @@ public class HttpsUtils { return null; } + public static JSONObject doGet(String url, Map params , Map headers) { + String apiUrl = url; + StringBuffer param = new StringBuffer(); + int i = 0; + for (String key : params.keySet()) { + if (i == 0) + param.append("?"); + else + param.append("&"); + param.append(key).append("=").append(params.get(key)); + i++; + } + apiUrl += param; + String result = null; + HttpClient httpClient = null; + try { + + if (apiUrl.startsWith("https")) { + httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory()) + .setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build(); + } else { + httpClient = HttpClients.createDefault(); + } + + HttpGet httpGet = new HttpGet(apiUrl); + for (Map.Entry e : headers.entrySet()) { + httpGet.addHeader(e.getKey(), e.getValue()); + } + HttpResponse response = httpClient.execute(httpGet); + HttpEntity entity = response.getEntity(); + if (entity != null) { + InputStream instream = entity.getContent(); + result = IOUtils.toString(instream, "UTF-8"); + } + return JSON.parseObject(result); + } catch (Exception e) { + log.error(e.getMessage(),e); + } + return null; + } + public static JSONObject doWxGet(String url, Map params) { String apiUrl = url; StringBuffer param = new StringBuffer(); @@ -159,6 +199,8 @@ public class HttpsUtils { } return null; } + +// public static JSONObject doGet(String url ,) /** * 发送 POST 请求(HTTP),不带输入数据 @@ -464,7 +506,7 @@ public class HttpsUtils { * @param url API地址 * @return */ - public static String postData(String url, String str) { + public static JSONObject postData(String url, String str) { CloseableHttpClient httpClient = null; if (url.startsWith("https")) { httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory()) @@ -482,11 +524,10 @@ public class HttpsUtils { StringEntity stringEntity = new StringEntity(str, "UTF-8");// 解决中文乱码问题 httpPost.addHeader("Content-Type", "text/xml"); httpPost.setEntity(stringEntity); - - HttpResponse httpResponse = httpClient.execute(httpPost); - HttpEntity httpEntity = httpResponse.getEntity(); - return EntityUtils.toString(httpEntity, "UTF-8"); - + response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + httpStr = EntityUtils.toString(entity, "UTF-8"); + return JSON.parseObject(httpStr); } catch (Exception e) { log.error(e.getMessage(),e); } finally { diff --git a/hai-service/src/main/java/com/hai/model/OutTelModel.java b/hai-service/src/main/java/com/hai/model/OutTelModel.java new file mode 100644 index 00000000..03a25449 --- /dev/null +++ b/hai-service/src/main/java/com/hai/model/OutTelModel.java @@ -0,0 +1,48 @@ +package com.hai.model; + +public class OutTelModel { + + // 地区 + private String province; + + // 城市 + private String city; + + // 运营商 + private String company; + + // 运营商识别码 + private String cardtype; + + public String getProvince() { + return province; + } + + public void setProvince(String province) { + this.province = province; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getCompany() { + return company; + } + + public void setCompany(String company) { + this.company = company; + } + + public String getCardtype() { + return cardtype; + } + + public void setCardtype(String cardtype) { + this.cardtype = cardtype; + } +} diff --git a/hai-service/src/main/java/com/hai/service/TelApiService.java b/hai-service/src/main/java/com/hai/service/TelApiService.java index bb1b5b8b..b26c61bf 100644 --- a/hai-service/src/main/java/com/hai/service/TelApiService.java +++ b/hai-service/src/main/java/com/hai/service/TelApiService.java @@ -1,6 +1,8 @@ package com.hai.service; +import com.alibaba.fastjson.JSONObject; import com.hai.entity.HighTelOrder; +import com.hai.model.OutTelModel; import java.util.List; import java.util.Map; @@ -58,4 +60,9 @@ public interface TelApiService { * @return java.lang.String **/ String telApiNotify(Map paramsMap) throws Exception; + + + JSONObject outApiTel(String tel); + + } diff --git a/hai-service/src/main/java/com/hai/service/impl/TelApiServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/TelApiServiceImpl.java index 9768ff45..74b87c80 100644 --- a/hai-service/src/main/java/com/hai/service/impl/TelApiServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/TelApiServiceImpl.java @@ -1,7 +1,10 @@ package com.hai.service.impl; +import com.alibaba.fastjson.JSONObject; +import com.hai.common.utils.HttpsUtils; import com.hai.dao.HighTelOrderMapper; import com.hai.entity.HighTelOrder; +import com.hai.model.OutTelModel; import com.hai.service.TelApiService; import com.hai.service.pay.PayService; import com.hai.service.pay.impl.NotifyServiceImpl; @@ -12,6 +15,7 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -72,4 +76,15 @@ public class TelApiServiceImpl implements TelApiService { return resXml; } + + @Override + public JSONObject outApiTel(String tel) { + + String appcode = "c4c79f70e40840959a1515b7cef7a70e"; + Map headers = new HashMap(); + headers.put("Authorization", "APPCODE " + appcode); + Map querys = new HashMap(); + querys.put("shouji", tel); + return HttpsUtils.doGet("https://jshmgsdmfb.market.alicloudapi.com/shouji/query", querys , headers); + } }