提交修改

dev-discount
袁野 4 years ago
parent 172ca427ff
commit 14adbf45ba
  1. 21
      hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java
  2. 55
      hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java
  3. 48
      hai-service/src/main/java/com/hai/model/OutTelModel.java
  4. 7
      hai-service/src/main/java/com/hai/service/TelApiService.java
  5. 15
      hai-service/src/main/java/com/hai/service/impl/TelApiServiceImpl.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);
}
}
}

@ -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<String, String> params , Map<String , String> 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<String, String> 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<String, Object> params) {
String apiUrl = url;
StringBuffer param = new StringBuffer();
@ -160,6 +200,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 {

@ -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;
}
}

@ -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<String, String> paramsMap) throws Exception;
JSONObject outApiTel(String tel);
}

@ -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<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "APPCODE " + appcode);
Map<String, String> querys = new HashMap<String, String>();
querys.put("shouji", tel);
return HttpsUtils.doGet("https://jshmgsdmfb.market.alicloudapi.com/shouji/query", querys , headers);
}
}

Loading…
Cancel
Save