|
|
|
@@ -6,20 +6,35 @@ import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.domain.po.WxPark; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.service.park.impl.haikangweishi.entity.ChallengeCode; |
|
|
|
import com.iformall.utils.HashUtil; |
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.http.HttpEntity; |
|
|
|
import org.apache.http.HttpResponse; |
|
|
|
import org.apache.http.NameValuePair; |
|
|
|
import org.apache.http.client.ClientProtocolException; |
|
|
|
import org.apache.http.client.entity.UrlEncodedFormEntity; |
|
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
|
import org.apache.http.entity.ContentType; |
|
|
|
import org.apache.http.entity.StringEntity; |
|
|
|
import org.apache.http.entity.mime.HttpMultipartMode; |
|
|
|
import org.apache.http.entity.mime.MultipartEntity; |
|
|
|
import org.apache.http.entity.mime.MultipartEntityBuilder; |
|
|
|
import org.apache.http.entity.mime.content.StringBody; |
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
import org.apache.http.impl.client.HttpClients; |
|
|
|
import org.apache.http.message.BasicNameValuePair; |
|
|
|
import org.apache.http.protocol.HTTP; |
|
|
|
import org.apache.http.util.EntityUtils; |
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStreamReader; |
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.nio.charset.Charset; |
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
@@ -41,9 +56,11 @@ import java.util.Map; |
|
|
|
public class HaiKangWeiShiUtil { |
|
|
|
|
|
|
|
public static final String TOKEN_URL = "https://open.hikyun.com/artemis/oauth/token"; |
|
|
|
public static final String CHALLENGE_CODE = "https://open.hikyun.com/artemis/api/eits/v1/challengeCode"; |
|
|
|
public static final String AUTHROZITAION = "https://open.hikyun.com/artemis/api/eits/v1/login"; |
|
|
|
public static final String GET_FEE = "https://open.hikyun.com/api/pmsc/v1/pay/ quickGetVehicleBill"; |
|
|
|
public static final String COUPON_USE = "https://open.hikyun.com/api/pmsc/v1/coupon/addition"; |
|
|
|
public static final String SUBSCRIPTION = "https://open.hikyun.com/api/pmsc/v1/sub/subscription"; |
|
|
|
public static final String SUBSCRIPTION = "https://open.hikyun.com/artemis/api/pmsc/v1/sub/subscription"; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@@ -70,43 +87,120 @@ public class HaiKangWeiShiUtil { |
|
|
|
public String getToken(WxPark wxPark) { |
|
|
|
String vendroParams = wxPark.getVendorParams(); |
|
|
|
JSONObject vp = JSON.parseObject(vendroParams); |
|
|
|
String clientId = vp.getString("AppKey"); |
|
|
|
String clientSecret = vp.getString("SecretKey"); |
|
|
|
String clientId = vp.getString("clientId"); |
|
|
|
String clientSecret = vp.getString("clientSecret"); |
|
|
|
return getToken(clientId,clientSecret); |
|
|
|
} |
|
|
|
|
|
|
|
private ChallengeCode getChallengeCode(WxPark wxPark,String accessToken) { |
|
|
|
String vendroParams = wxPark.getVendorParams(); |
|
|
|
JSONObject vp = JSON.parseObject(vendroParams); |
|
|
|
Map<String,Object> params = new HashMap<String,Object>(); |
|
|
|
params.put("name", vp.getString("pmsName"));//pms.hikyun.com 的账号 |
|
|
|
params.put("productCode", vp.getString("productCode")); |
|
|
|
params.put("type", "1"); |
|
|
|
String retCode = ProcBussiness(CHALLENGE_CODE, params,accessToken,null); |
|
|
|
if (StringUtils.isBlank(retCode)) { |
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "haikang getChallengeCode error. has no result"); |
|
|
|
} |
|
|
|
JSONObject result = JSON.parseObject(retCode); |
|
|
|
|
|
|
|
Integer errStatus = result.getInteger("status"); |
|
|
|
if (null != errStatus) { |
|
|
|
throw new MallinkException(errStatus,"haikang getChallengeCode error.["+result.getString("error")+"]"+result.getString("message")); |
|
|
|
} |
|
|
|
|
|
|
|
if (!result.getString("code").equals("200") ) { |
|
|
|
String message = result.getString("msg"); |
|
|
|
throw new MallinkException(result.getInteger("code"), "haikang getChallengeCode error."+message); |
|
|
|
} |
|
|
|
JSONObject attribute = result.getJSONObject("data"); |
|
|
|
if (null == attribute) { |
|
|
|
throw new MallinkException(result.getInteger("code"), "haikang getChallengeCode error. no result"); |
|
|
|
} |
|
|
|
return new ChallengeCode(attribute.getString("pwdStatus"),attribute.getString("codeId"),attribute.getString("salt"),attribute.getString("vCode")); |
|
|
|
} |
|
|
|
|
|
|
|
private static String entryPmsPassword(String password,String salt,String vCode) { |
|
|
|
return HashUtil.sha256(HashUtil.sha256(password+salt)+vCode); |
|
|
|
} |
|
|
|
|
|
|
|
//使用后不能再次使用,并且有很短的过期时间 |
|
|
|
public String getAuthorization(WxPark wxPark,String accessToken) { |
|
|
|
String vendroParams = wxPark.getVendorParams(); |
|
|
|
JSONObject vp = JSON.parseObject(vendroParams); |
|
|
|
ChallengeCode challengeCode = getChallengeCode(wxPark,accessToken); |
|
|
|
Map<String,Object> params = new HashMap<String,Object>(); |
|
|
|
params.put("name", vp.getString("pmsName"));//pms.hikyun.com 的账号 |
|
|
|
params.put("productCode", vp.getString("productCode")); |
|
|
|
params.put("type", "1"); |
|
|
|
params.put("codeId", challengeCode.getCodeId()); |
|
|
|
params.put("password", entryPmsPassword(vp.getString("pmsPassword"),challengeCode.getSalt(),challengeCode.getVCode())); |
|
|
|
String retCode = ProcBussiness(AUTHROZITAION, params,accessToken,null); |
|
|
|
if (StringUtils.isBlank(retCode)) { |
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "haikang getAuthorization error. has no result"); |
|
|
|
} |
|
|
|
JSONObject result = JSON.parseObject(retCode); |
|
|
|
|
|
|
|
Integer errStatus = result.getInteger("status"); |
|
|
|
if (null != errStatus) { |
|
|
|
throw new MallinkException(errStatus,"haikang getAuthorization error.["+result.getString("error")+"]"+result.getString("message")); |
|
|
|
} |
|
|
|
|
|
|
|
if (!result.getString("code").equals("200") ) { |
|
|
|
String message = result.getString("msg"); |
|
|
|
throw new MallinkException(result.getInteger("code"), "haikang getAuthorization error."+message); |
|
|
|
} |
|
|
|
JSONObject attribute = result.getJSONObject("data"); |
|
|
|
if (null == attribute) { |
|
|
|
throw new MallinkException(result.getInteger("code"), "haikang getAuthorization error. no result"); |
|
|
|
} |
|
|
|
return attribute.getString("Authorization"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private String getToken(String clientId,String clientSecret) { |
|
|
|
String result = ProcLogin(clientId, clientSecret); |
|
|
|
log.info("haikang token clientId:"+clientId+" clientSecret:"+clientSecret+" result: "+result); |
|
|
|
if (StringUtils.isBlank(result)) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
JSONObject res = JSON.parseObject(result); |
|
|
|
Integer code = res.getInteger("code"); |
|
|
|
if (null == code || code.intValue() != 0) { |
|
|
|
String msg = res.getString("msg"); |
|
|
|
throw new MallinkException(code,msg); |
|
|
|
Integer errStatus = res.getInteger("status"); |
|
|
|
if (null != errStatus) { |
|
|
|
throw new MallinkException(errStatus,"haikang access_token error.["+res.getString("error")+"]"+res.getString("message")); |
|
|
|
} |
|
|
|
|
|
|
|
String accessToken = res.getString("access_token"); |
|
|
|
if (null != accessToken ) { |
|
|
|
return accessToken; |
|
|
|
}else { |
|
|
|
throw new MallinkException(500,"haikang access_token error.["+res.getString("error")+"]"+res.getString("error_description")); |
|
|
|
} |
|
|
|
return res.getString("access_token"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询停车费 3.5.5 快速获取账单接口 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public JSONObject getFee(WxPark wxPark,String carNumber,String token) { |
|
|
|
public JSONObject getFee(WxPark wxPark,String carNumber,String token,String Authrozitaion) { |
|
|
|
String vendroParams = wxPark.getVendorParams(); |
|
|
|
JSONObject vp = JSON.parseObject(vendroParams); |
|
|
|
ArrayList<NameValuePair> list = new ArrayList<NameValuePair>(); |
|
|
|
list.add(new BasicNameValuePair("chargeSource", "THIRD"));//商户编号 |
|
|
|
list.add(new BasicNameValuePair("parkId", wxPark.getParkingId())); |
|
|
|
list.add(new BasicNameValuePair("plateNo", carNumber)); |
|
|
|
String retCode= ProcBussiness(GET_FEE, list, token); |
|
|
|
Map<String,Object> params = new HashMap<String,Object>(); |
|
|
|
params.put("chargeSource", "THIRD");//商户编号 |
|
|
|
params.put("parkId", wxPark.getParkingId()); |
|
|
|
params.put("plateNo", carNumber); |
|
|
|
String retCode= ProcBussiness(GET_FEE, params, token,Authrozitaion); |
|
|
|
if (StringUtils.isBlank(retCode)) { |
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "haikang getFee error. has no result"); |
|
|
|
} |
|
|
|
JSONObject result = JSON.parseObject(retCode); |
|
|
|
if (result.getInteger("code") != 0 ) { |
|
|
|
|
|
|
|
Integer errStatus = result.getInteger("status"); |
|
|
|
if (null != errStatus) { |
|
|
|
throw new MallinkException(errStatus,"haikang getFee error.["+result.getString("error")+"]"+result.getString("message")); |
|
|
|
} |
|
|
|
|
|
|
|
if (!result.getString("code").equals("200") ) { |
|
|
|
String message = result.getString("msg"); |
|
|
|
throw new MallinkException(result.getInteger("code"), "haikang getFee error."+message); |
|
|
|
} |
|
|
|
@@ -126,20 +220,26 @@ public class HaiKangWeiShiUtil { |
|
|
|
完成一次优惠缴费 |
|
|
|
* 使用优惠券 3.5.9.1接口进行车牌和优惠信息绑定优惠券后,车辆出场时会自动抵扣 |
|
|
|
**/ |
|
|
|
public JSONObject useCoupon(WxPark wxPark,String couponNo,String carNumber,String orderNo,String token){ |
|
|
|
public JSONObject useCoupon(WxPark wxPark,String couponNo,String carNumber,String orderNo,String token,String Authrozitaion){ |
|
|
|
String vendroParams = wxPark.getVendorParams(); |
|
|
|
JSONObject vp = JSON.parseObject(vendroParams); |
|
|
|
ArrayList<NameValuePair> list = new ArrayList<NameValuePair>(); |
|
|
|
Map<String,Object> params = new HashMap<String,Object>(); |
|
|
|
Map couponmap = new HashMap(); |
|
|
|
couponmap.put("plateNo", carNumber); |
|
|
|
couponmap.put("ruleId", couponNo); |
|
|
|
list.add(new BasicNameValuePair("coupons", "["+JSON.toJSONString(couponmap)+"]") );//商户编号 |
|
|
|
String retCode = ProcBussiness(COUPON_USE, list,token); |
|
|
|
params.put("coupons", "["+JSON.toJSONString(couponmap)+"]");//商户编号 |
|
|
|
String retCode = ProcBussiness(COUPON_USE, params,token,Authrozitaion); |
|
|
|
if (StringUtils.isBlank(retCode)) { |
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "haikang useCoupon error. has no result"); |
|
|
|
} |
|
|
|
JSONObject result = JSON.parseObject(retCode); |
|
|
|
if (result.getInteger("code") != 0 ) { |
|
|
|
|
|
|
|
Integer errStatus = result.getInteger("status"); |
|
|
|
if (null != errStatus) { |
|
|
|
throw new MallinkException(errStatus,"haikang useCoupon error.["+result.getString("error")+"]"+result.getString("message")); |
|
|
|
} |
|
|
|
|
|
|
|
if (!result.getString("code").equals("200") ) { |
|
|
|
String message = result.getString("msg"); |
|
|
|
throw new MallinkException(result.getInteger("code"), "haikang useCoupon error."+message); |
|
|
|
} |
|
|
|
@@ -148,26 +248,39 @@ public class HaiKangWeiShiUtil { |
|
|
|
|
|
|
|
/** |
|
|
|
* 消息订阅 3.1.8 |
|
|
|
* * 这个接口需要你们实现的时候规定下: |
|
|
|
1、POST格式, |
|
|
|
2、接口返回参数JSON格式:{errcode:0, errmsg: "success",data:null} |
|
|
|
3、接口建议接收到过车事件,立即返回接收成功 |
|
|
|
|
|
|
|
我这边根据这个 0 状态来判断你们是否接收成功,如果没成功,我这边会重发3次的 |
|
|
|
* |
|
|
|
* @param clientId |
|
|
|
* @param clientSecret |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public JSONObject subscription(WxPark wxPark,String couponNo,String carNumber,String orderNo,String token){ |
|
|
|
public JSONObject subscription(WxPark wxPark,String token,String Authrozitaion){ |
|
|
|
String vendroParams = wxPark.getVendorParams(); |
|
|
|
JSONObject vp = JSON.parseObject(vendroParams); |
|
|
|
ArrayList<NameValuePair> list = new ArrayList<NameValuePair>(); |
|
|
|
list.add(new BasicNameValuePair("partnerAppKey", vp.getString("AppKey")));//商户编号 |
|
|
|
list.add(new BasicNameValuePair("projectId", vp.getString("projectId"))); |
|
|
|
list.add(new BasicNameValuePair("eventTypes", carNumber)); |
|
|
|
list.add(new BasicNameValuePair("subUrl", vp.getString("subUrl"))); |
|
|
|
String retCode = ProcBussiness(SUBSCRIPTION, list,token); |
|
|
|
Map<String,Object> params = new HashMap<String,Object>(); |
|
|
|
params.put("partnerAppKey", vp.getString("ak"));//商户编号 |
|
|
|
params.put("projectId", vp.getString("projectId")); |
|
|
|
params.put("eventTypes", new Integer[] {771760131,771760134}); |
|
|
|
params.put("subUrl", vp.getString("subUrl")); |
|
|
|
String retCode = ProcBussiness(SUBSCRIPTION, params,token,Authrozitaion); |
|
|
|
if (StringUtils.isBlank(retCode)) { |
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "haikang useCoupon error. has no result"); |
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "haikang subscription error. has no result"); |
|
|
|
} |
|
|
|
JSONObject result = JSON.parseObject(retCode); |
|
|
|
if (result.getInteger("code") != 0 ) { |
|
|
|
|
|
|
|
Integer errStatus = result.getInteger("status"); |
|
|
|
if (null != errStatus) { |
|
|
|
throw new MallinkException(errStatus,"haikang subscription error.["+result.getString("error")+"]"+result.getString("message")); |
|
|
|
} |
|
|
|
|
|
|
|
if (!result.getString("code").equals("0") ) { |
|
|
|
String message = result.getString("msg"); |
|
|
|
throw new MallinkException(result.getInteger("code"), "haikang useCoupon error."+message); |
|
|
|
throw new MallinkException(result.getInteger("code"), "haikang subscription error."+message); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
@@ -177,12 +290,13 @@ public class HaiKangWeiShiUtil { |
|
|
|
ArrayList<NameValuePair> list = new ArrayList<NameValuePair>(); |
|
|
|
list.add(new BasicNameValuePair("client_id", clientId)); |
|
|
|
list.add(new BasicNameValuePair("client_secret", clientSecret)); |
|
|
|
return Proc(TOKEN_URL,list,null,null); |
|
|
|
return formData(TOKEN_URL,list,null,null); |
|
|
|
} |
|
|
|
|
|
|
|
private static String ProcBussiness(String url,ArrayList<NameValuePair> list,String token) { |
|
|
|
|
|
|
|
|
|
|
|
private static String ProcBussiness(String url,Map<String,Object> list,String token,String authorization) { |
|
|
|
try { |
|
|
|
String authorization = ""; |
|
|
|
return Proc(url,list,token,authorization); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("haikang request error.",e); |
|
|
|
@@ -190,13 +304,10 @@ public class HaiKangWeiShiUtil { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private static String Proc(String url, List<NameValuePair> pairs,String token,String authorization) { |
|
|
|
private static String Proc(String url, Map<String,Object> pairs,String token,String authorization) { |
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault(); |
|
|
|
|
|
|
|
HttpPost httpPost = new HttpPost(url); |
|
|
|
httpPost.addHeader(HTTP.CONTENT_TYPE,"application/json"); |
|
|
|
httpPost.addHeader("Accept", "application/json"); |
|
|
|
httpPost.addHeader("Accept-Encoding", "UTF-8"); |
|
|
|
if (!StringUtils.isBlank(token)) { |
|
|
|
httpPost.addHeader("access_token",token); |
|
|
|
} |
|
|
|
@@ -205,15 +316,13 @@ public class HaiKangWeiShiUtil { |
|
|
|
} |
|
|
|
|
|
|
|
if (null != pairs) { |
|
|
|
HttpEntity en; |
|
|
|
try { |
|
|
|
en = new UrlEncodedFormEntity(pairs, HTTP.UTF_8); |
|
|
|
httpPost.setEntity(en); |
|
|
|
try { |
|
|
|
StringEntity entity = new StringEntity(JSON.toJSONString(pairs)); |
|
|
|
entity.setContentType("application/json"); |
|
|
|
httpPost.setEntity(entity); |
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
log.error(e.getLocalizedMessage(),e); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (null != pairs) { |
|
|
|
@@ -248,4 +357,56 @@ public class HaiKangWeiShiUtil { |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private static String formData(String url,List<NameValuePair> pairs,String token,String authorization) { |
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault(); |
|
|
|
HttpPost httpPost = new HttpPost(url); |
|
|
|
if (!StringUtils.isBlank(token)) { |
|
|
|
httpPost.addHeader("access_token",token); |
|
|
|
} |
|
|
|
if (!StringUtils.isBlank(authorization)) { |
|
|
|
httpPost.addHeader("Authorization",authorization); |
|
|
|
} |
|
|
|
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); |
|
|
|
if (null != pairs) { |
|
|
|
for (NameValuePair nvp : pairs) { |
|
|
|
builder.addPart(nvp.getName(), new StringBody(nvp.getValue(),ContentType.TEXT_PLAIN)); |
|
|
|
} |
|
|
|
} |
|
|
|
HttpEntity entity = builder.build(); |
|
|
|
httpPost.setEntity(entity); |
|
|
|
|
|
|
|
if (null != pairs) { |
|
|
|
log.info("haikangweishi httpRequest:[url]"+url+"[params]"+JSON.toJSONString(pairs)); |
|
|
|
}else { |
|
|
|
log.info("haikangweishi httpRequest:[url]"+url); |
|
|
|
} |
|
|
|
HttpResponse response = null; |
|
|
|
try { |
|
|
|
response = httpClient.execute(httpPost); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error(e.getLocalizedMessage(),e); |
|
|
|
} |
|
|
|
|
|
|
|
String result = null; |
|
|
|
|
|
|
|
//打印StatusLine |
|
|
|
log.debug("StatusLine: " + response.getStatusLine()); |
|
|
|
try{ |
|
|
|
//获取实体 |
|
|
|
HttpEntity httpEntity= response.getEntity(); |
|
|
|
result = EntityUtils.toString(httpEntity, "UTF-8"); |
|
|
|
log.debug(result); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error(e.getLocalizedMessage(),e); |
|
|
|
} |
|
|
|
|
|
|
|
try { //关闭流并释放资源 |
|
|
|
httpClient.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error(e.getLocalizedMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |