Просмотр исходного кода

fix alipay

release_toaliyun_real
xiaohanzi 5 лет назад
Родитель
Сommit
51aa7865c8
4 измененных файлов: 77 добавлений и 53 удалений
  1. +1
    -1
      mallinkAdmin/src/main/java/com/iformall/controller/pay/AlipayController.java
  2. +37
    -21
      mallinkCallback/src/main/java/com/iformall/controller/callback/AliPayController.java
  3. +27
    -21
      mallinkService/src/main/java/com/iformall/service/pay/alipay/AliPayUtil.java
  4. +12
    -10
      mallinkService/src/main/java/com/iformall/service/pay/alipay/api/AliPayApi.java

+ 1
- 1
mallinkAdmin/src/main/java/com/iformall/controller/pay/AlipayController.java Просмотреть файл

@@ -158,7 +158,7 @@ public class AlipayController extends BaseController {
} }
if (!StringUtils.isBlank(wxMall.getAlipayMemberTemplateId())) { if (!StringUtils.isBlank(wxMall.getAlipayMemberTemplateId())) {
return new ResultData(Result.ERROR,"已经创建过模板,不能重复创建");
return new ResultData(Result.ERROR,"已经创建过模板,不能重复创建. 重新生成,则C端的授权地址需要重新生成");
} }
try { try {


+ 37
- 21
mallinkCallback/src/main/java/com/iformall/controller/callback/AliPayController.java Просмотреть файл

@@ -38,6 +38,18 @@ public class AliPayController extends BaseController {
@Autowired @Autowired
private AliPayCUserService aliPayCUserService; private AliPayCUserService aliPayCUserService;
private void writeResponse(HttpServletResponse response,String msg) {
PrintWriter out;
try {
out = response.getWriter();
out.print(msg);
out.close();
} catch (IOException e) {
logger.error(" alipayCallback writeResponse error.",e);
}
}
/** /**
* 支付宝客户端回调接口 * 支付宝客户端回调接口
* 1. 商圈授权给isv后的回调。 isv账号登陆开放平台(https://openhome.alipay.com),选择平台应用,菜单“商家授权应用-发起授权”,复制链接或二维码给商圈支付宝账号扫。 * 1. 商圈授权给isv后的回调。 isv账号登陆开放平台(https://openhome.alipay.com),选择平台应用,菜单“商家授权应用-发起授权”,复制链接或二维码给商圈支付宝账号扫。
@@ -55,28 +67,32 @@ public class AliPayController extends BaseController {
if (null == outString) { if (null == outString) {
outString = ""; outString = "";
} }
PrintWriter out = response.getWriter();
//商家授权给ISV后的回调 //商家授权给ISV后的回调
if ("alipay_app_auth".equals(source)) { if ("alipay_app_auth".equals(source)) {
String tenantId = request.getParameter("state"); String tenantId = request.getParameter("state");
if (StringUtils.isBlank(tenantId)) { if (StringUtils.isBlank(tenantId)) {
out.print("Param Error!tenantId is null.");
writeResponse(response,"Param Error!tenantId is null.");
return;
}else { }else {
WxMall wxMall = mallService.getByTenantId(tenantId); WxMall wxMall = mallService.getByTenantId(tenantId);
if (null == wxMall ) { if (null == wxMall ) {
out.print("Auth Failed!wxMall not fond.");
writeResponse(response,"Auth Failed!wxMall not fond.");
return;
}else { }else {
String appAuthCode = request.getParameter("app_auth_code"); String appAuthCode = request.getParameter("app_auth_code");
if (StringUtils.isBlank(appAuthCode)) { if (StringUtils.isBlank(appAuthCode)) {
out.print("Auth Failed!app_auth_code is null.");
writeResponse(response,"Auth Failed!app_auth_code is null.");
return;
}else { }else {
String token = alipayUtil.getAppAuthToken(appAuthCode); String token = alipayUtil.getAppAuthToken(appAuthCode);
if (StringUtils.isBlank(token)) { if (StringUtils.isBlank(token)) {
out.print("Auth Failed!token is empity , Retry.");
writeResponse(response,"Auth Failed!token is empity , Retry.");
return;
}else { }else {
wxMall.setAlipayAppAuthToken(token); wxMall.setAlipayAppAuthToken(token);
mallService.update(wxMall); mallService.update(wxMall);
out.print("Auth success!.");
writeResponse(response,"Auth success!.");
return;
} }
} }
} }
@@ -90,22 +106,27 @@ public class AliPayController extends BaseController {
String tenantId = args[1]; String tenantId = args[1];
WxMall wxMall = mallService.getByTenantId(tenantId); WxMall wxMall = mallService.getByTenantId(tenantId);
if (null == wxMall ) { if (null == wxMall ) {
out.print("Auth Failed!wxMall not fond.");
writeResponse(response,"Auth Failed!wxMall not fond.");
return;
} }
if (null == wxMall.getAlipayAppAuthToken() || "".equals(wxMall.getAlipayAppAuthToken()) ) { if (null == wxMall.getAlipayAppAuthToken() || "".equals(wxMall.getAlipayAppAuthToken()) ) {
out.print("Auth Failed!wxMall alipayAppToken is null.");
writeResponse(response,"Auth Failed!wxMall alipayAppToken is null.");
return;
}else { }else {
UserAuthData authData = alipayUtil.queryUserAuthData(wxMall.getAlipayAppAuthToken(), authCode); UserAuthData authData = alipayUtil.queryUserAuthData(wxMall.getAlipayAppAuthToken(), authCode);
if (null == authData ) { if (null == authData ) {
out.print("Auth Failed!queryUserAuthData return null.");
writeResponse(response,"Auth Failed!queryUserAuthData return null.");
return;
}else { }else {
Map<EnumMemberCardConfig,Object> map = alipayUtil.queryUserFormData(wxMall.getAlipayAppAuthToken(), authData.getAccessToken(), templateId, requestId); Map<EnumMemberCardConfig,Object> map = alipayUtil.queryUserFormData(wxMall.getAlipayAppAuthToken(), authData.getAccessToken(), templateId, requestId);
if (null == map) { if (null == map) {
out.print("Auth Failed!queryUserFormData return null.");
writeResponse(response,"Auth Failed!queryUserFormData return null.");
return;
}else { }else {
String phone = (String) map.get(EnumMemberCardConfig.OPEN_FORM_FIELD_MOBILE); String phone = (String) map.get(EnumMemberCardConfig.OPEN_FORM_FIELD_MOBILE);
if (StringUtils.isBlank(phone)) { if (StringUtils.isBlank(phone)) {
out.print("Auth Failed! Phone is Empity.");
writeResponse(response,"Auth Failed! Phone is Empity.");
return;
}else { }else {
//查询该userId是否已经开卡,已经开卡不再开卡 //查询该userId是否已经开卡,已经开卡不再开卡
AliPayCUser query = new AliPayCUser(); AliPayCUser query = new AliPayCUser();
@@ -126,20 +147,18 @@ public class AliPayController extends BaseController {
//跳转到商圈积分授权页面 //跳转到商圈积分授权页面
String pointsUrl = alipayUtil.getH5SmartDistrictMallVipPointsUrl(tenantId); String pointsUrl = alipayUtil.getH5SmartDistrictMallVipPointsUrl(tenantId);
if (null != alicuser.getCardOpen() && alicuser.getCardOpen() > 0) { if (null != alicuser.getCardOpen() && alicuser.getCardOpen() > 0) {
out.print("Auth success!.");
out.close();
response.sendRedirect(pointsUrl); response.sendRedirect(pointsUrl);
return;
}else { }else {
boolean opencard = alipayUtil.openCard(wxMall.getAlipayAppAuthToken(), authData.getAccessToken(), templateId, authData.getUserId()); boolean opencard = alipayUtil.openCard(wxMall.getAlipayAppAuthToken(), authData.getAccessToken(), templateId, authData.getUserId());
if (opencard) { if (opencard) {
alicuser.setCardOpen(1); alicuser.setCardOpen(1);
aliPayCUserService.saveOrUpdate(alicuser); aliPayCUserService.saveOrUpdate(alicuser);
out.print("Auth success!.");
out.close();
//跳转到商圈积分授权页面 //跳转到商圈积分授权页面
response.sendRedirect(pointsUrl); response.sendRedirect(pointsUrl);
}else { }else {
out.print("Auth Failed!");
writeResponse(response,"Auth Failed!");
return;
} }
} }
} }
@@ -147,12 +166,9 @@ public class AliPayController extends BaseController {
} }
}//商圈节分授权 }//商圈节分授权
}else if ("mall_vip_points".equals(scope)) { }else if ("mall_vip_points".equals(scope)) {
out.print("Auth success!.");
writeResponse(response,"Auth success!.");
return;
} }
try {
out.close();
}catch(Exception e) {
}
} }
/** /**


+ 27
- 21
mallinkService/src/main/java/com/iformall/service/pay/alipay/AliPayUtil.java Просмотреть файл

@@ -230,12 +230,18 @@ public class AliPayUtil {
public UserAuthData queryUserAuthData(String appAuthToken,String authCode) { public UserAuthData queryUserAuthData(String appAuthToken,String authCode) {
try { try {
AlipayOpenApiGenericResponse response = AliPayApi.queryUserAuthData(getConfig(), appAuthToken, authCode); AlipayOpenApiGenericResponse response = AliPayApi.queryUserAuthData(getConfig(), appAuthToken, authCode);
JSONObject result = getGenericResponse(response.getHttpBody(),"alipay_system_oauth_token_response");
if (null != result) {
UserAuthData authData = new UserAuthData();
authData.setUserId(result.getString("user_id"));
authData.setAccessToken(result.getString("access_token"));
return authData;
//JSONObject result = getGenericResponse(response.getHttpBody(),"alipay_system_oauth_token_response");
JSONObject responseResult = JSON.parseObject(response.getHttpBody());
if (null != responseResult) {
JSONObject result = responseResult.getJSONObject("alipay_system_oauth_token_response");
if (null != result) {
UserAuthData authData = new UserAuthData();
authData.setUserId(result.getString("user_id"));
authData.setAccessToken(result.getString("access_token"));
return authData;
}else {
log.error("alipay queryUserAuthData error. "+response.getHttpBody());
}
} }
} catch (Exception e) { } catch (Exception e) {
log.error("alipay queryUserAuthData error. ",e); log.error("alipay queryUserAuthData error. ",e);
@@ -261,8 +267,8 @@ public class AliPayUtil {
Map<EnumMemberCardConfig,Object> map = new HashMap<EnumMemberCardConfig,Object>(); Map<EnumMemberCardConfig,Object> map = new HashMap<EnumMemberCardConfig,Object>();
for (int i = 0 ; i < infosArray.size(); i++) { for (int i = 0 ; i < infosArray.size(); i++) {
Map<String,Object> jo = (Map<String,Object>)infosArray.get(i); Map<String,Object> jo = (Map<String,Object>)infosArray.get(i);
String[] keys = (String[]) jo.keySet().toArray();
EnumMemberCardConfig config = EnumMemberCardConfig.getEnum(keys[0]);
Object[] keys = jo.keySet().toArray();
EnumMemberCardConfig config = EnumMemberCardConfig.getEnum(String.valueOf(keys[0]));
if (null != config) { if (null != config) {
map.put(config, jo.get(keys[0])); map.put(config, jo.get(keys[0]));
} }
@@ -295,7 +301,7 @@ public class AliPayUtil {
//商圈消息订阅 //商圈消息订阅
public boolean smartDistrictTopicSubscribe(String appAuthToken) { public boolean smartDistrictTopicSubscribe(String appAuthToken) {
try { try {
AlipayOpenApiGenericResponse response = AliPayApi.topicSubscribe(getConfig(),appAuthToken,appAuthToken, "app_auth", "alipay.open.auth.appauth.cancelled", "HTTP", "BIZ_TAG");
AlipayOpenApiGenericResponse response = AliPayApi.topicSubscribe(getConfig(),appAuthToken, "app_auth", "alipay.open.auth.appauth.cancelled", "HTTP", "BIZ_TAG");
JSONObject result = getGenericResponse(response.getHttpBody(),"alipay_open_app_message_topic_subscribe_response"); JSONObject result = getGenericResponse(response.getHttpBody(),"alipay_open_app_message_topic_subscribe_response");
if (null != result) { if (null != result) {
return true; return true;
@@ -329,17 +335,17 @@ public class AliPayUtil {
return buffer; return buffer;
} }
public static void main(String[] args) {
AliPayUtil util = new AliPayUtil();
// String token = getAppAuthToken("Pfbe94a5103a0414db99ce865204ee63");
// System.out.println(token);
//File file = new File("C://logo-img.png");
//System.out.println(util.merchantImageUpload("202104BB054c88e950ba4513854e4275ff71cF63", "aa.jpg", File2byte(file)));
//System.out.println(util.createSmartDistrictMemberCardModel("202104BB054c88e950ba4513854e4275ff71cF63", "会员卡", "OKJx3oOPTUOaINs0AQ_qMgAAACMAAQQD", "OKJx3oOPTUOaINs0AQ_qMgAAACMAAQQD"));
//System.out.println(util.setSmartDistrictMemberCardModelConfig("202104BB054c88e950ba4513854e4275ff71cF63", "20210417000000002702655000300637"));
//System.out.println(util.getSmartDistrictMemberCardUrl("202104BB054c88e950ba4513854e4275ff71cF63", "20210417000000002702655000300637", "https://ctest.malls.iformall.com/C/api/alipay/callback", "123"));
//System.out.println(util.getH5SmartDistrictMallVipPointsUrl("2021002139648762", "https://ctest.malls.iformall.com/C/api/alipay/callback", "123"));
System.out.println(util.smartDistrictTopicSubscribe("202104BB054c88e950ba4513854e4275ff71cF63"));
}
// public static void main(String[] args) {
// AliPayUtil util = new AliPayUtil();
//// String token = getAppAuthToken("Pfbe94a5103a0414db99ce865204ee63");
//// System.out.println(token);
// //File file = new File("C://logo-img.png");
// //System.out.println(util.merchantImageUpload("202104BB054c88e950ba4513854e4275ff71cF63", "aa.jpg", File2byte(file)));
// //System.out.println(util.createSmartDistrictMemberCardModel("202104BB054c88e950ba4513854e4275ff71cF63", "会员卡", "OKJx3oOPTUOaINs0AQ_qMgAAACMAAQQD", "OKJx3oOPTUOaINs0AQ_qMgAAACMAAQQD"));
// //System.out.println(util.setSmartDistrictMemberCardModelConfig("202104BB054c88e950ba4513854e4275ff71cF63", "20210417000000002702655000300637"));
// //System.out.println(util.getSmartDistrictMemberCardUrl("202104BB054c88e950ba4513854e4275ff71cF63", "20210417000000002702655000300637", "https://ctest.malls.iformall.com/C/api/alipay/callback", "123"));
// //System.out.println(util.getH5SmartDistrictMallVipPointsUrl("2021002139648762", "https://ctest.malls.iformall.com/C/api/alipay/callback", "123"));
// System.out.println(util.smartDistrictTopicSubscribe("202104BB054c88e950ba4513854e4275ff71cF63"));
// }
} }

+ 12
- 10
mallinkService/src/main/java/com/iformall/service/pay/alipay/api/AliPayApi.java Просмотреть файл

@@ -221,13 +221,10 @@ public class AliPayApi {
//设置系统参数(OpenAPI中非biz_content里的参数) //设置系统参数(OpenAPI中非biz_content里的参数)
Map<String, String> textParams = new HashMap<String, String>(); Map<String, String> textParams = new HashMap<String, String>();
textParams.put("app_auth_token", appAuthToken); textParams.put("app_auth_token", appAuthToken);

//设置业务参数(OpenAPI中biz_content里的参数)
Map<String, Object> bizParams = new HashMap<String, Object>();
bizParams.put("grant_type", "authorization_code");
bizParams.put("authorization_code", authCode);
textParams.put("grant_type", "authorization_code");
textParams.put("code", authCode);
AlipayOpenApiGenericResponse response = Factory.Util.Generic().execute( AlipayOpenApiGenericResponse response = Factory.Util.Generic().execute(
"alipay.system.oauth.token", textParams, bizParams);
"alipay.system.oauth.token", textParams, null);
return response; return response;
} }
@@ -281,6 +278,7 @@ public class AliPayApi {
Map<String,Object> extInfoMap = new HashMap<String,Object>(); Map<String,Object> extInfoMap = new HashMap<String,Object>();
extInfoMap.put("open_date", new Date()); extInfoMap.put("open_date", new Date());
extInfoMap.put("valid_date", DateUtils.stringToDate("2051-05-01 00:00:00",DateUtils.DATE_TIME_PATTERN)); extInfoMap.put("valid_date", DateUtils.stringToDate("2051-05-01 00:00:00",DateUtils.DATE_TIME_PATTERN));
extInfoMap.put("external_card_no",String.valueOf(idWorker.nextId()));
bizParams.put("card_ext_info", extInfoMap); bizParams.put("card_ext_info", extInfoMap);
AlipayOpenApiGenericResponse response = Factory.Util.Generic().execute( AlipayOpenApiGenericResponse response = Factory.Util.Generic().execute(
@@ -292,14 +290,18 @@ public class AliPayApi {
/** /**
* https://opendocs.alipay.com/apis/api_9/alipay.open.app.message.topic.subscribe * https://opendocs.alipay.com/apis/api_9/alipay.open.app.message.topic.subscribe
* 订阅消息主题 * 订阅消息主题
*
* 需要联系BD 给商圈挂载“支付宝商圈交易成功信息订阅”功能包
* https://openhome.alipay.com/svr/ability/solution/SC00001010/xxdy (对接会员卡的应用AppId用ISV的应用ID)
*
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static AlipayOpenApiGenericResponse topicSubscribe(Config config,String appAuthToken,String authToken,String authType,String topic,String type,String tag) throws Exception {
public static AlipayOpenApiGenericResponse topicSubscribe(Config config,String authToken,String authType,String topic,String type,String tag) throws Exception {
Factory.setOptions(config); Factory.setOptions(config);
//设置系统参数(OpenAPI中非biz_content里的参数) //设置系统参数(OpenAPI中非biz_content里的参数)
Map<String, String> textParams = new HashMap<String, String>();
textParams.put("app_auth_token", appAuthToken);
//Map<String, String> textParams = new HashMap<String, String>();
//textParams.put("app_auth_token", appAuthToken);


//设置业务参数(OpenAPI中biz_content里的参数) //设置业务参数(OpenAPI中biz_content里的参数)
Map<String, Object> bizParams = new HashMap<String, Object>(); Map<String, Object> bizParams = new HashMap<String, Object>();
@@ -311,7 +313,7 @@ public class AliPayApi {
bizParams.put("tag",tag); bizParams.put("tag",tag);
} }
AlipayOpenApiGenericResponse response = Factory.Util.Generic().execute( AlipayOpenApiGenericResponse response = Factory.Util.Generic().execute(
"alipay.open.app.message.topic.subscribe", textParams, bizParams);
"alipay.open.app.message.topic.subscribe", null, bizParams);
return response; return response;
} }
} }

Загрузка…
Отмена
Сохранить