Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

生产中应用时发现偶尔会出现access_token过期,因为刷新失败了,加入重试机制,直到成功 #199

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions src/main/java/weixin/popular/api/PayVeticleAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package weixin.popular.api;

import java.nio.charset.Charset;
import java.util.Map;

import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.entity.StringEntity;

import weixin.popular.bean.vehicle.EntranceNotification;
import weixin.popular.bean.vehicle.EntranceNotificationResult;
import weixin.popular.bean.vehicle.NavigateToAppForAuth;
import weixin.popular.bean.vehicle.NavigateToAppForAuthExtraData;
import weixin.popular.bean.vehicle.PayApply;
import weixin.popular.bean.vehicle.PayApplyResult;
import weixin.popular.bean.vehicle.QueryState;
import weixin.popular.bean.vehicle.QueryStateResult;
import weixin.popular.client.LocalHttpClient;
import weixin.popular.util.JsonUtil;
import weixin.popular.util.MapUtil;
import weixin.popular.util.SignatureUtil;
import weixin.popular.util.XMLConverUtil;

/**
* 车主服务
*
* @author around
*
*/
public class PayVeticleAPI extends BaseAPI {

/**
* 入场通知
*
* @param notification
* @param key
* @return
*/
public static EntranceNotificationResult entranceNotification(EntranceNotification notification, String key) {
Map<String, String> map = MapUtil.objectToMap(notification);
if (notification.getScene_info() != null) {
map.put("scene_info", "{\"scene_info\":" + JsonUtil.toJSONString(notification.getScene_info()) + "}");
}
String sign = SignatureUtil.generateSign(map, notification.getSign_type(), key);
notification.setSign(sign);
String xml = XMLConverUtil.convertToXML(notification);
HttpUriRequest httpUriRequest = RequestBuilder.post().setHeader(xmlHeader).setUri(MCH_URI + "/vehicle/partnerpay/notification")
.setEntity(new StringEntity(xml, Charset.forName("utf-8"))).build();
return LocalHttpClient.executeXmlResult(httpUriRequest, EntranceNotificationResult.class, notification.getSign_type(), key);
}

/**
* 扣款请求
*
* @param apply
* @param key
* @return
*/
public static PayApplyResult payApply(PayApply apply, String key) {
Map<String, String> map = MapUtil.objectToMap(apply);
if (apply.getScene_info() != null) {
map.put("scene_info", "{\"scene_info\":" + JsonUtil.toJSONString(apply.getScene_info()) + "}");
}
String sign = SignatureUtil.generateSign(map, apply.getSign_type(), key);
apply.setSign(sign);
String xml = XMLConverUtil.convertToXML(apply);
HttpUriRequest httpUriRequest = RequestBuilder.post().setHeader(xmlHeader).setUri(MCH_URI + "/vehicle/partnerpay/payapply").setEntity(new StringEntity(xml, Charset.forName("utf-8")))
.build();
return LocalHttpClient.executeXmlResult(httpUriRequest, PayApplyResult.class, apply.getSign_type(), key);
}

/**
* 查询
*
* @param query
* @param key
* @return
*/
public static QueryStateResult queryState(QueryState query, String key) {
Map<String, String> map = MapUtil.objectToMap(query);
String sign = SignatureUtil.generateSign(map, query.getSign_type(), key);
query.setSign(sign);
String xml = XMLConverUtil.convertToXML(query);
HttpUriRequest httpUriRequest = RequestBuilder.post().setHeader(xmlHeader).setUri(MCH_URI + "/vehicle/partnerpay/querystate")
.setEntity(new StringEntity(xml, Charset.forName("utf-8"))).build();
return LocalHttpClient.executeXmlResult(httpUriRequest, QueryStateResult.class, query.getSign_type(), key);
}

public static NavigateToAppForAuth navigateToMappForAuth(String path, String tradeScene, String appid, String subAppid, String mchid, String subMchid, String openid, String subOpenid,
String plateNumber, String materialInfo, String channelType, String key) {
NavigateToAppForAuth nav = new NavigateToAppForAuth();
nav.setPath(path);
NavigateToAppForAuthExtraData extraData = new NavigateToAppForAuthExtraData();
extraData.setAppid(appid);
extraData.setSub_appid(subAppid);
extraData.setMch_id(mchid);
extraData.setSub_mch_id(subMchid);
extraData.setTrade_scene(tradeScene);
extraData.setOpenid(openid);
extraData.setSub_openid(subOpenid);
extraData.setChannel_type(channelType);
extraData.setMaterial_info(materialInfo);
if ("HIGHWAY".equalsIgnoreCase(tradeScene)) {
extraData.setPlate_number(plateNumber);
}
extraData.setNonce_str(String.valueOf(System.currentTimeMillis()));
Map<String, String> map = MapUtil.objectToMap(extraData);
extraData.setSign(SignatureUtil.generateSign(map, key));
nav.setExtra_data(extraData);
return nav;
}

/**
* 支付中开通车主服务,需要申请开通权限
*
* @param oldAttach
* @param plateNumber
* @param appid
* @return
*/
public static String openServiceWhenPaying(String oldAttach, String plateNumber, String appid) {
return String.format("#*#{\"pn\":\"%s\",\"aid\":\"%s\"}#*#%s", plateNumber, appid, oldAttach);
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
package weixin.popular.bean.paymch;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
* 刷卡支付 授权码查询OPENID 返回数据
* @author LiYi
*
*/
@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)
public class AuthcodetoopenidResult extends MchBase{

@XmlElement
private String openid;

@XmlElement
private String sub_openid;

public String getOpenid() {
return openid;
}

public void setOpenid(String openid) {
this.openid = openid;
}

public String getSub_openid() {
return sub_openid;
}

public void setSub_openid(String sub_openid) {
this.sub_openid = sub_openid;
}



}
package weixin.popular.bean.paymch;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
* 刷卡支付 授权码查询OPENID 返回数据
*
* @author LiYi
*
*/
@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)
public class AuthcodetoopenidResult extends MchBase {

@XmlElement
private String openid;
@XmlElement
private String sub_openid;

public String getOpenid() {
return openid;
}

public void setOpenid(String openid) {
this.openid = openid;
}

public String getSub_openid() {
return sub_openid;
}

public void setSub_openid(String sub_openid) {
this.sub_openid = sub_openid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package weixin.popular.bean.vehicle;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

/**
* 入场通知
*
* @author around
*
*/
@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)
public class EntranceNotification extends VehicleBaseReq {

// 格式为json...
@XmlJavaTypeAdapter(value = SceneInfo.JsonXmlAdapter.class)
private SceneInfo scene_info;

// 委托代扣的交易场景值,目前支持 : 1. PARKING:车场停车场景 ;2. PARKING SPACE 车位停车场景;该值催缴时会向微信用户进行展示
private String trade_scene;

/**
* @return the 场景信息
*/
public final SceneInfo getScene_info() {
return scene_info;
}

/**
* @param 场景信息
* to set
*/
public final void setScene_info(SceneInfo scene_info) {
this.scene_info = scene_info;
}

/**
* @return 场景
*/
public final String getTrade_scene() {
return trade_scene;
}

/**
* @param 场景
* to set
*/
public final void setTrade_scene(String trade_scene) {
this.trade_scene = trade_scene;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package weixin.popular.bean.vehicle;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

/**
* 入场通知结果
*
* @author around
*
*/
@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)
public class EntranceNotificationResult extends VehicleBaseResult {

private String appid;
private String sub_appid;
private String mch_id;
private String sub_mch_id;
private String nonce_str;
private String sign;
private String result_code;
private String err_code;
private String err_code_des;
private String user_state;
private String openid;
private String sub_openid;

public final String getAppid() {
return appid;
}

public final void setAppid(String appid) {
this.appid = appid;
}

public final String getSub_appid() {
return sub_appid;
}

public final void setSub_appid(String sub_appid) {
this.sub_appid = sub_appid;
}

public final String getMch_id() {
return mch_id;
}

public final void setMch_id(String mch_id) {
this.mch_id = mch_id;
}

public final String getSub_mch_id() {
return sub_mch_id;
}

public final void setSub_mch_id(String sub_mch_id) {
this.sub_mch_id = sub_mch_id;
}

public final String getNonce_str() {
return nonce_str;
}

public final void setNonce_str(String nonce_str) {
this.nonce_str = nonce_str;
}

public final String getSign() {
return sign;
}

public final void setSign(String sign) {
this.sign = sign;
}

public final String getResult_code() {
return result_code;
}

public final void setResult_code(String result_code) {
this.result_code = result_code;
}

public final String getErr_code() {
return err_code;
}

public final void setErr_code(String err_code) {
this.err_code = err_code;
}

public final String getErr_code_des() {
return err_code_des;
}

public final void setErr_code_des(String err_code_des) {
this.err_code_des = err_code_des;
}

public final String getUser_state() {
return user_state;
}

public final void setUser_state(String user_state) {
this.user_state = user_state;
}

public final String getOpenid() {
return openid;
}

public final void setOpenid(String openid) {
this.openid = openid;
}

public final String getSub_openid() {
return sub_openid;
}

public final void setSub_openid(String sub_openid) {
this.sub_openid = sub_openid;
}

}
Loading