| @@ -143,4 +143,42 @@ public class CallbackPayController extends BaseController { | |||||
| return resultMap; | return resultMap; | ||||
| } | } | ||||
| @AuthIgnore | |||||
| @ApiOperation("支付回调") | |||||
| @PostMapping(value = "/aliNotify") | |||||
| public Map<String,Object> _aliNotify(@RequestBody Map<String, Object> paranMap, HttpServletRequest request, HttpServletResponse response) { | |||||
| logger.debug("[" + getIpAddr() + "] CallbackPayController::_aliNotify"); | |||||
| Map<String,Object> resultMap = new HashMap<>(); | |||||
| logger.info("ali支付回调结果通知{}"+JSONObject.toJSONString(paranMap)); | |||||
| /** | |||||
| * ----效验数据来源合法 | |||||
| */ | |||||
| try{ | |||||
| // String msg = (String) paranMap.get("msg"); | |||||
| // String type = (String) paranMap.get("type"); | |||||
| // | |||||
| // Map<String, Object> pMap = JSONObject.parseObject(msg, Map.class); | |||||
| // String appid = (String) pMap.get("appid"); | |||||
| // WxAppinfo appInfo = wxAppinfoService.getOnlyByAppIdFromRedis(appid); | |||||
| // WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); | |||||
| // if("payment".equals(type)){ | |||||
| // String out_order_no = (String)pMap.get("cp_orderno"); | |||||
| // | |||||
| // EnumProductOrderPayVendor payVendorEnum = EnumProductOrderPayVendor.PAY_WAY_TT; | |||||
| // ProductOrderPay orderPay = productOrderPayService.getByOrder(Long.parseLong(out_order_no), payVendorEnum); | |||||
| // | |||||
| // PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(payVendorEnum.getCode()); | |||||
| // productOrderPayService.handleProductOrderByQuery(appInfo,payAccount,orderPay,payAdapterService); | |||||
| // | |||||
| // resultMap.put("err_no",0); | |||||
| // resultMap.put("err_tips","success"); | |||||
| // } | |||||
| }catch(Exception e){ | |||||
| logger.error("抖音支付回调处理异常"+e); | |||||
| resultMap.put("err_no",ErrorCode.SYS_SERVER_ERROR.getCode()); | |||||
| resultMap.put("err_tips","抖音支付回调处理异常"); | |||||
| } | |||||
| return resultMap; | |||||
| } | |||||
| } | } | ||||
| @@ -40,11 +40,12 @@ | |||||
| <artifactId>suimang-mybatis</artifactId> | <artifactId>suimang-mybatis</artifactId> | ||||
| <version>1.0</version> | <version>1.0</version> | ||||
| </dependency> | </dependency> | ||||
| <dependency> | <dependency> | ||||
| <groupId>com.alipay.sdk</groupId> | |||||
| <artifactId>alipay-easysdk</artifactId> | |||||
| <version>2.2.0</version> | |||||
| </dependency> | |||||
| <groupId>com.alipay.sdk</groupId> | |||||
| <artifactId>alipay-sdk-java</artifactId> | |||||
| <version>4.38.98.ALL</version> | |||||
| </dependency> | |||||
| </dependencies> | </dependencies> | ||||
| </project> | </project> | ||||
| @@ -1,357 +0,0 @@ | |||||
| package com.iformall.service.pay.alipay; | |||||
| import java.io.ByteArrayOutputStream; | |||||
| import java.io.File; | |||||
| import java.io.FileInputStream; | |||||
| import java.io.FileNotFoundException; | |||||
| import java.io.FileOutputStream; | |||||
| import java.io.IOException; | |||||
| import java.io.UnsupportedEncodingException; | |||||
| import java.net.URLEncoder; | |||||
| import java.util.ArrayList; | |||||
| import java.util.HashMap; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| import java.util.Set; | |||||
| import java.util.UUID; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Component; | |||||
| import org.springframework.stereotype.Service; | |||||
| import com.alibaba.fastjson.JSON; | |||||
| import com.alibaba.fastjson.JSONArray; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.alipay.easysdk.base.image.models.AlipayOfflineMaterialImageUploadResponse; | |||||
| import com.alipay.easysdk.base.oauth.models.AlipaySystemOauthTokenResponse; | |||||
| import com.alipay.easysdk.kernel.Config; | |||||
| import com.alipay.easysdk.util.generic.models.AlipayOpenApiGenericResponse; | |||||
| import com.iformall.service.pay.alipay.api.AliPayApi; | |||||
| import com.iformall.service.pay.alipay.api.enums.EnumMemberCardConfig; | |||||
| import com.iformall.service.pay.alipay.api.reqEntity.AlipayMemberCardModelColumn; | |||||
| import com.iformall.service.pay.alipay.api.reqEntity.AlipayMemberCardModelFieldRule; | |||||
| import com.iformall.service.pay.alipay.api.reqEntity.AlipayMemberCardModelRequest; | |||||
| import com.iformall.service.pay.alipay.api.reqEntity.AlipayMemberCardModelStyle; | |||||
| import com.iformall.service.pay.alipay.api.result.UserAuthData; | |||||
| import com.iformall.service.pay.alipay.config.AliPayConfig; | |||||
| import lombok.extern.slf4j.Slf4j; | |||||
| @Component | |||||
| @Slf4j | |||||
| public class AliPayUtil { | |||||
| @Autowired | |||||
| AliPayConfig payConfig; | |||||
| private Config getConfig() { | |||||
| //AliPayConfig payConfig = new AliPayConfig(); | |||||
| //payConfig.setAppId("2021002137663024"); | |||||
| //payConfig.setAppPrivateKey("MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCUfymV5J73QQMG52PVIGUbowkloYCO4B7TQoKbrTZf2YeYsg/To/o4PiXPMNwEUfEUU8NYQ6WwNhCd2fa1ei8WFXJUf3bfgswtBk1aOmHLeY9yoXFxIKMTQ9RcobnmBzKQZlaAPMTSr7t1QtKZKPuc2gEHGRFYKO/ZuL8gIpnsVidVtmi52yd7hzao/pI3ThLA0lreg4L3rYP5ESQZRytxIPgUQ4KI11pZxFgbe+uy28AGDYIQscSIb+SWOHPYKLvOEqqepIZ8M18w/U0lZzpzepzi/V/llekvXJ6UEf1lzl7x/4UIA3WPN1B40+NzbD/OxEGTuM0UctOG6ZTd4Te9AgMBAAECggEAPYksnHbvARspu/SrRCh2fatkIPn6Ijrxyy3mnch7neCw9i/jqxpqmF/4nxFqO0gRlRDZBHyT7p+Y5zDpsW5+kLI2fJmNkzXKkmXoLBnBaOZo8WHBdtXFfjg/iltig9Y7t+cQtXd5QK2eCwuz5dA75FXa0ywqKdRdAGY0nYZ5LpwrHVU8RXheUDCJyhKNj2+W6lIaSKDxLZU3laO1oBrv1agcy7Crd5E2ndb8O3Enga+z7wSz2h7A1BasC/Yl/Ro0Y21wLCH3s/R6qA0Paq12+WEF+xdodM7SrP43CCTVFGbC1TfEOdanJfixop8QuYsIp7pHrL925+vP4eY9RfckgQKBgQDQqLdpDzzU7Ot/L9Vc/r8d4iwXXbX8+HwVFV4oBuausgFyv8eJJpfrI+IlEoB1ubJcPpJBFqfmeYTW6/v6ioFljJAlWfFvesUVt/HszBMIOsU0Bzt7ex6WlwKOagb0q0ZPA4T0OY0K0lg0loaaaR8ZTr4ivDymaGBtTBYhslpc7QKBgQC2MBznGEc5r2dhyENvdPOR20PnXQcevGnPdqSus8m0VmDcHE72RVcckcZtwczsb3NaLSqmjAcWTn51/VFmlvhB3F34FcFTPZGq6sj7fWK8HuFq7l7mu5OzYuVr73zy9ggsUuaw10IqvvwIVxszNAF0hiRnSGH3z27CoRmz3s+8EQKBgQCK3o7atBJ3X4rIJiypbL4DhIB1uJ+jUjk6yvLUTut+fufp1+tTw0S+cS5UIAEw2Lr1G4u5F/v8rwmTBJG6SC4gSLGyui6uVBYRA1BWmedcxchzfRDAeMt9y9kesUAZ3Fe5xIzbAeZ1ulKMBVZmM+pHrJlsgr0Wv0bV1xqvqITtbQKBgBIsIGXopQoa9dvqBtfyOW1eCprkS5aEQqWf9vM6Ga90QjsSU8n6xqKh48IE57TZtQ7UnIF6TCasc66/MsRh4KdpHLJnMR5lcMc0nhF/wz5ychehaTPol+X3wlyOyc7OPah2KG6ROhdbb3ZBggQMduyxiKYIsUTvmuOtAAxR+DSRAoGADtuDzGQDOJYWiO2uuP6FpA5IJaiwlSfu3xncJVfhO8SVr6VBJFg88igbIB3w6nk/sv7j9VTXqXre9HMvp1flxaaLsdxM4HcTSALS9q6t/ajaveqte6S5kAtWx0WW8C6PtgWXHbxcD7LXARSsKLoEl2JXXyUVS/m2l/RzHBQ8GJI="); | |||||
| //payConfig.setAppPublicKeyCertPath("C://appCertPublicKey_2021002137663024.crt"); | |||||
| //payConfig.setAlipayCertPath("C://alipayCertPublicKey_RSA2.crt"); | |||||
| //payConfig.setAlipayRootCertPath("C://alipayRootCert.crt"); | |||||
| return AliPayApi.getOptions(payConfig.getAppId(), payConfig.getAppPrivateKey(), payConfig.getAppPublicKeyCertPath(), | |||||
| payConfig.getAlipayCertPath(), payConfig.getAlipayRootCertPath()); | |||||
| } | |||||
| private String getCallBack() { | |||||
| //AliPayConfig payConfig = new AliPayConfig(); | |||||
| //payConfig.setCallback("https://callbacktest.malls.iformall.com/api/alipay/notify/callback"); | |||||
| return payConfig.getCallback(); | |||||
| } | |||||
| //第三方应用授权 | |||||
| public String getAppAuthUrl(String param) { | |||||
| try { | |||||
| return AliPayApi.getAppAuthUrl(getConfig(), getCallBack(), param); | |||||
| } catch (UnsupportedEncodingException e) { | |||||
| log.error("alipay getMerchantAuthUrl error. ",e); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| //查询app_auth_token | |||||
| public String getAppAuthToken(String appAuthCode) { | |||||
| try { | |||||
| AlipayOpenApiGenericResponse response = AliPayApi.getAppAuthToken(getConfig(),appAuthCode); | |||||
| JSONObject result = getGenericResponse(response.getHttpBody(),"alipay_open_auth_token_app_response"); | |||||
| if (null != result) { | |||||
| JSONArray arrays = result.getJSONArray("tokens"); | |||||
| if (null != arrays) { | |||||
| JSONObject resutl0 =arrays.getJSONObject(0); | |||||
| return resutl0.getString("app_auth_token"); | |||||
| }else { | |||||
| log.error("alipay getAppAuthToken error. ",response.getHttpBody()); | |||||
| } | |||||
| } | |||||
| } catch (Exception e) { | |||||
| log.error("alipay getAppAuthToken error. ",e); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private static JSONObject getGenericResponseWithCodes(String result,String key,String[] successCodes) { | |||||
| if (StringUtils.isBlank(result)) { | |||||
| log.error("alipay apiresponse ["+key+"] error. no result."+result); | |||||
| return null; | |||||
| } | |||||
| JSONObject object = JSON.parseObject(result); | |||||
| if (null != object) { | |||||
| JSONObject resultObject = object.getJSONObject(key); | |||||
| if (null != resultObject ) { | |||||
| String code = resultObject.getString("code"); | |||||
| for (String successCode : successCodes) { | |||||
| if ((successCode.equals(code))) { | |||||
| return resultObject; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| log.error("alipay apiresponse ["+key+"] error. "+result); | |||||
| return null; | |||||
| } | |||||
| private static JSONObject getGenericResponse(String result,String key) { | |||||
| return getGenericResponseWithCodes(result,key,new String[] {"10000"}); | |||||
| } | |||||
| //门店照片上传 | |||||
| public String merchantImageUpload(String appAuthToken,String imageName,byte[] file) { | |||||
| String temfolder = "/alipaytempfile/"+UUID.randomUUID(); | |||||
| File tempfolerFile = new File(temfolder); | |||||
| if (!tempfolerFile.exists()) { | |||||
| tempfolerFile.mkdirs(); | |||||
| } | |||||
| String temFilePath = temfolder+"/"+imageName; | |||||
| File f = new File(temFilePath); | |||||
| if (f.exists()) { | |||||
| f.delete(); | |||||
| } | |||||
| try { | |||||
| FileOutputStream fos = new FileOutputStream(f); | |||||
| fos.write(file); | |||||
| fos.close(); | |||||
| AlipayOfflineMaterialImageUploadResponse response = AliPayApi.uploadMerchantImage(getConfig(),appAuthToken,imageName, temFilePath); | |||||
| JSONObject result = getGenericResponse(response.getHttpBody(),"alipay_offline_material_image_upload_response"); | |||||
| if (f.exists()) { | |||||
| f.delete(); | |||||
| } | |||||
| if (null != result) { | |||||
| return result.getString("image_id"); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| if (f.exists()) { | |||||
| f.delete(); | |||||
| } | |||||
| log.error("alipay merchantImageUpload error. ",e); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| //创建商圈会员卡 | |||||
| public String createSmartDistrictMemberCardModel(String appAuthToken,String cardName,String logoId,String backImageId) { | |||||
| AlipayMemberCardModelRequest request = new AlipayMemberCardModelRequest(); | |||||
| AlipayMemberCardModelStyle style = new AlipayMemberCardModelStyle(); | |||||
| style.setCard_show_name(cardName); | |||||
| style.setLogo_id(logoId); | |||||
| style.setBackground_id(backImageId); | |||||
| request.setTemplate_style_info(style); | |||||
| List<AlipayMemberCardModelColumn> columnList = new ArrayList<AlipayMemberCardModelColumn>(); | |||||
| AlipayMemberCardModelColumn column0 = new AlipayMemberCardModelColumn(); | |||||
| column0.setCode("TELEPHONE"); | |||||
| column0.setTitle("联系电话"); | |||||
| columnList.add(column0); | |||||
| AlipayMemberCardModelColumn column1 = new AlipayMemberCardModelColumn(); | |||||
| column1.setCode("BENEFIT_INFO"); | |||||
| column1.setTitle("会员专享"); | |||||
| columnList.add(column1); | |||||
| request.setColumn_info_list(columnList); | |||||
| List<AlipayMemberCardModelFieldRule> ruleList = new ArrayList<AlipayMemberCardModelFieldRule>(); | |||||
| AlipayMemberCardModelFieldRule rule0 = new AlipayMemberCardModelFieldRule(); | |||||
| rule0.setField_name("Balance"); | |||||
| rule0.setRule_name("ASSIGN_FROM_REQUEST"); | |||||
| rule0.setRule_value("Balance"); | |||||
| ruleList.add(rule0); | |||||
| request.setField_rule_list(ruleList); | |||||
| try { | |||||
| AlipayOpenApiGenericResponse response = AliPayApi.createMemberCardModel(getConfig(),appAuthToken, request); | |||||
| JSONObject result = getGenericResponse(response.getHttpBody(),"alipay_marketing_card_template_create_response"); | |||||
| if (null != result) { | |||||
| return result.getString("template_id"); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| log.error("alipay createSmartDistrictMemberCardModel error. ",e); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| //创建商圈会员卡表单配置 | |||||
| public boolean setSmartDistrictMemberCardModelConfig(String appAuthToken,String templateId) { | |||||
| try { | |||||
| // AlipayOpenApiGenericResponse response = AliPayApi.setMemberCardModelConfig(getConfig(),appAuthToken, templateId, | |||||
| // new String[] {EnumMemberCardConfig.OPEN_FORM_FIELD_MOBILE.getCode()},new String[] {EnumMemberCardConfig.OPEN_FORM_FIELD_NAME.getCode()}); | |||||
| AlipayOpenApiGenericResponse response = AliPayApi.setMemberCardModelConfig(getConfig(),appAuthToken, templateId, | |||||
| new String[] {EnumMemberCardConfig.OPEN_FORM_FIELD_MOBILE.getCode()},null); | |||||
| JSONObject result = getGenericResponse(response.getHttpBody(),"alipay_marketing_card_formtemplate_set_response"); | |||||
| if (null != result) { | |||||
| return true; | |||||
| } | |||||
| } catch (Exception e) { | |||||
| log.error("alipay setSmartDistrictMemberCardModelConfig error. ",e); | |||||
| } | |||||
| return false; | |||||
| } | |||||
| //获取商圈会员卡领卡投放链接 | |||||
| public String getSmartDistrictMemberCardUrl(String appAuthToken,String templateId,String param) { | |||||
| try { | |||||
| AlipayOpenApiGenericResponse response = AliPayApi.getMemberCardUrl(getConfig(),appAuthToken, templateId, param, getCallBack()); | |||||
| JSONObject result = getGenericResponse(response.getHttpBody(),"alipay_marketing_card_activateurl_apply_response"); | |||||
| if (null != result) { | |||||
| return result.getString("apply_card_url"); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| log.error("alipay getSmartDistrictMemberCardUrl error. ",e); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| //商圈智能积分授权(算法授权)URL | |||||
| public String getH5SmartDistrictMallVipPointsUrl(String param) { | |||||
| try { | |||||
| return "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id="+getConfig().appId+"&scope=mall_vip_points&redirect_uri="+URLEncoder.encode(getCallBack(),"utf-8")+"&state="+param; | |||||
| } catch (UnsupportedEncodingException e) { | |||||
| log.error("alipay getH5MallVipPointsUrl error. ",e); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| //获取用户授权令牌 | |||||
| public UserAuthData queryUserAuthData(String appAuthToken,String authCode) { | |||||
| try { | |||||
| AlipayOpenApiGenericResponse response = AliPayApi.queryUserAuthData(getConfig(), appAuthToken, authCode); | |||||
| //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) { | |||||
| log.error("alipay queryUserAuthData error. ",e); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| //查询用户表单信息 | |||||
| public Map<EnumMemberCardConfig,Object> queryUserFormData(String appAuthToken,String authToken,String templateId,String requestId) { | |||||
| try { | |||||
| AlipayOpenApiGenericResponse response = AliPayApi.queryUserFormData(getConfig(), appAuthToken, authToken, templateId, requestId); | |||||
| JSONObject result = getGenericResponse(response.getHttpBody(),"alipay_marketing_card_activateform_query_response"); | |||||
| if (null != result) { | |||||
| String infos = result.getString("infos"); | |||||
| if (StringUtils.isBlank(infos)) { | |||||
| return null; | |||||
| } | |||||
| JSONArray infosArray = JSON.parseArray(infos); | |||||
| if (null == infosArray) { | |||||
| return null; | |||||
| } | |||||
| Map<EnumMemberCardConfig,Object> map = new HashMap<EnumMemberCardConfig,Object>(); | |||||
| for (int i = 0 ; i < infosArray.size(); i++) { | |||||
| Map<String,Object> jo = (Map<String,Object>)infosArray.get(i); | |||||
| Object[] keys = jo.keySet().toArray(); | |||||
| EnumMemberCardConfig config = EnumMemberCardConfig.getEnum(String.valueOf(keys[0])); | |||||
| if (null != config) { | |||||
| map.put(config, jo.get(keys[0])); | |||||
| } | |||||
| } | |||||
| if (map.isEmpty()) { | |||||
| return null; | |||||
| } | |||||
| return map; | |||||
| } | |||||
| } catch (Exception e) { | |||||
| log.error("alipay queryUserFormData error. ",e); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| //用户开卡 | |||||
| public boolean openCard(String appAuthToken,String authToken,String templateId,String userId) { | |||||
| try { | |||||
| AlipayOpenApiGenericResponse response = AliPayApi.openCard(getConfig(), appAuthToken, authToken, templateId, userId); | |||||
| JSONObject result = getGenericResponse(response.getHttpBody(),"alipay_marketing_card_open_response"); | |||||
| if (null != result) { | |||||
| return true; | |||||
| } | |||||
| } catch (Exception e) { | |||||
| log.error("alipay openCard error. ",e); | |||||
| } | |||||
| return false; | |||||
| } | |||||
| //商圈消息订阅 | |||||
| public boolean smartDistrictTopicSubscribe(String appAuthToken,String topic) { | |||||
| try { | |||||
| AlipayOpenApiGenericResponse response = AliPayApi.topicSubscribe(getConfig(),appAuthToken, "app_auth", topic, "HTTP", "BIZ_TAG"); | |||||
| JSONObject result = getGenericResponseWithCodes(response.getHttpBody(),"alipay_open_app_message_topic_subscribe_response",new String[] {"40004","10000"}); | |||||
| if (null != result) { | |||||
| return true; | |||||
| } | |||||
| } catch (Exception e) { | |||||
| log.error("alipay smartDistrictTopicSubscribe error. ",e); | |||||
| } | |||||
| return false; | |||||
| } | |||||
| public static byte[] File2byte(File tradeFile){ | |||||
| byte[] buffer = null; | |||||
| try | |||||
| { | |||||
| FileInputStream fis = new FileInputStream(tradeFile); | |||||
| ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |||||
| byte[] b = new byte[1024]; | |||||
| int n; | |||||
| while ((n = fis.read(b)) != -1) | |||||
| { | |||||
| bos.write(b, 0, n); | |||||
| } | |||||
| fis.close(); | |||||
| bos.close(); | |||||
| buffer = bos.toByteArray(); | |||||
| }catch (FileNotFoundException e){ | |||||
| e.printStackTrace(); | |||||
| }catch (IOException e){ | |||||
| e.printStackTrace(); | |||||
| } | |||||
| 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","alipay.business.mall.trade.success")); | |||||
| } | |||||
| } | |||||
| @@ -1,319 +0,0 @@ | |||||
| package com.iformall.service.pay.alipay.api; | |||||
| import java.io.UnsupportedEncodingException; | |||||
| import java.net.URLEncoder; | |||||
| import java.util.Date; | |||||
| import java.util.HashMap; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| import java.util.UUID; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import com.alibaba.fastjson.JSON; | |||||
| import com.alipay.easysdk.base.image.models.AlipayOfflineMaterialImageUploadResponse; | |||||
| import com.alipay.easysdk.base.oauth.models.AlipaySystemOauthTokenResponse; | |||||
| import com.alipay.easysdk.factory.Factory; | |||||
| import com.alipay.easysdk.kernel.Config; | |||||
| import com.alipay.easysdk.util.generic.models.AlipayOpenApiGenericResponse; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.service.pay.alipay.api.reqEntity.AlipayMemberCardModelColumn; | |||||
| import com.iformall.service.pay.alipay.api.reqEntity.AlipayMemberCardModelFieldRule; | |||||
| import com.iformall.service.pay.alipay.api.reqEntity.AlipayMemberCardModelRequest; | |||||
| import com.iformall.service.pay.alipay.api.reqEntity.AlipayMemberCardModelStyle; | |||||
| import com.iformall.utils.DateUtils; | |||||
| /** | |||||
| * SDK说明 https://opendocs.alipay.com/open/54/00y8k9 | |||||
| * 综合体支付积分https://opendocs.alipay.com/open/01lsmc?scene=SC00001296 | |||||
| * @author alascor | |||||
| */ | |||||
| public class AliPayApi { | |||||
| /** | |||||
| * https://opendocs.alipay.com/open/291/105971 | |||||
| * @param | |||||
| * appId:应用ID, isv模式则为第三方应用ID, 非isv模式则为自研应用ID | |||||
| * appPrivateKey: 应用私钥字符串,isv模式则为第三方应用私钥, 非isv模式则为自研应用私钥。产生地址为https://miniu.alipay.com/keytool/create | |||||
| * appPublicKeyCertPath: 应用公钥文件本地地址。isv模式则为第三方应用公钥文件本地地址, 非isv模式则为自研应用公钥文件本地地址。 获取路径:https://open.alipay.com/dev/workspace/key-manage,"接口加签方式:"设置里面下载 | |||||
| * alipayCertPath: 支付宝公钥证书文件路径. isv模式则为第三方应用支付宝公钥证书文件路径, 非isv模式则为自研应用支付宝公钥证书文件路径。 | |||||
| * alipayRootCertPath: 支付宝根证书文件路径.isv模式则为第三方应用支付宝根证书文件路径, 非isv模式则为自研应用支付宝根证书文件路径。 | |||||
| * @return | |||||
| */ | |||||
| public static Config getOptions(String appId,String appPrivateKey,String appPublicKeyCertPath,String alipayCertPath,String alipayRootCertPath) { | |||||
| Config config = new Config(); | |||||
| config.protocol = "https"; | |||||
| config.gatewayHost = "openapi.alipay.com"; | |||||
| config.signType = "RSA2"; | |||||
| config.appId = appId; | |||||
| // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中 | |||||
| config.merchantPrivateKey = appPrivateKey; | |||||
| //#注:证书文件路径支持设置为文件系统中的路径或CLASS_PATH中的路径,优先从文件系统中加载,加载失败后会继续尝试从CLASS_PATH中加载 | |||||
| config.merchantCertPath = appPublicKeyCertPath; | |||||
| config.alipayCertPath = alipayCertPath; | |||||
| config.alipayRootCertPath = alipayRootCertPath; | |||||
| //#####注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可 | |||||
| //config.alipayPublicKey = appPublicKey; | |||||
| //可设置异步通知接收服务地址(可选) | |||||
| //config.notifyUrl = "<-- 请填写您的支付类接口异步通知接收服务地址,例如:https://www.test.com/callback -->"; | |||||
| //可设置AES密钥,调用AES加解密相关接口时需要(可选) | |||||
| //config.encryptKey = "<-- 请填写您的AES密钥,例如:aa4BtZ4tspm2wnXLb1ThQA== -->"; | |||||
| return config; | |||||
| } | |||||
| /** | |||||
| * https://opendocs.alipay.com/open/common/105193 | |||||
| * 第三方应用授权 | |||||
| * @throws UnsupportedEncodingException | |||||
| */ | |||||
| public static String getAppAuthUrl(Config config,String callback,String param) throws UnsupportedEncodingException { | |||||
| String paramstr = ""; | |||||
| if (!StringUtils.isBlank(param)) { | |||||
| paramstr = "&state="+param; | |||||
| } | |||||
| return "https://openauth.alipay.com/oauth2/appToAppBatchAuth.htm?app_id="+config.appId+"&application_type=TINYAPP,WEBAPP,MOBILEAPP,PUBLICAPP&redirect_uri="+URLEncoder.encode(callback, "utf-8")+paramstr; | |||||
| } | |||||
| /** | |||||
| * https://opendocs.alipay.com/open/common/105193 | |||||
| * https://opendocs.alipay.com/apis/api_9/alipay.open.auth.token.app | |||||
| * 换取应用授权令牌(非ISV模式) | |||||
| * @throws Exception | |||||
| */ | |||||
| // public static AlipaySystemOauthTokenResponse getAppAuthToken(Config config,String appAuthCode) throws Exception { | |||||
| // Factory.setOptions(config); | |||||
| // AlipaySystemOauthTokenResponse response = Factory.Base.OAuth().getToken(appAuthCode); | |||||
| // return response; | |||||
| // } | |||||
| /** | |||||
| * https://opendocs.alipay.com/support/01ratr | |||||
| * https://opendocs.alipay.com/apis/api_9/alipay.open.auth.token.app | |||||
| * 换取应用授权令牌(ISV模式) | |||||
| * @throws Exception | |||||
| */ | |||||
| public static AlipayOpenApiGenericResponse getAppAuthToken(Config config,String appAuthCode) throws Exception { | |||||
| Factory.setOptions(config); | |||||
| //设置系统参数(OpenAPI中非biz_content里的参数) | |||||
| //Map<String, String> textParams = new HashMap<String, String>(); | |||||
| //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("code",appAuthCode); | |||||
| AlipayOpenApiGenericResponse response = Factory.Util.Generic() | |||||
| .execute("alipay.open.auth.token.app", null, bizParams); | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * https://opendocs.alipay.com/apis/api_3/alipay.offline.material.image.upload | |||||
| * 上传门店照片和视频接口 | |||||
| * @throws Exception | |||||
| */ | |||||
| public static AlipayOfflineMaterialImageUploadResponse uploadMerchantImage(Config config,String appAuthToken,String imageName,String localImagePath) throws Exception { | |||||
| Factory.setOptions(config); | |||||
| AlipayOfflineMaterialImageUploadResponse response = Factory.Base.Image().agent(appAuthToken).upload(imageName, localImagePath); | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * https://opendocs.alipay.com/apis/api_5/alipay.marketing.card.template.create | |||||
| * 会员卡模板创建 | |||||
| * @throws Exception | |||||
| */ | |||||
| public static AlipayOpenApiGenericResponse createMemberCardModel(Config config,String appAuthToken,AlipayMemberCardModelRequest modelRequest) throws Exception { | |||||
| Factory.setOptions(config); | |||||
| //设置系统参数(OpenAPI中非biz_content里的参数) | |||||
| Map<String, String> textParams = new HashMap<String, String>(); | |||||
| textParams.put("app_auth_token", appAuthToken); | |||||
| //设置业务参数(OpenAPI中biz_content里的参数) | |||||
| Map<String, Object> bizParams = new HashMap<String, Object>(); | |||||
| IdWorker idWorker = IdWorker.get(); | |||||
| bizParams.put("request_id", String.valueOf(idWorker.nextId())); | |||||
| bizParams.put("card_type", modelRequest.getCard_type()); | |||||
| bizParams.put("biz_no_suffix_len",modelRequest.getBiz_no_suffix_len()); | |||||
| bizParams.put("write_off_type", modelRequest.getWrite_off_type()); | |||||
| AlipayMemberCardModelStyle style = modelRequest.getTemplate_style_info(); | |||||
| bizParams.put("template_style_info", style); | |||||
| List<AlipayMemberCardModelColumn> columnList = modelRequest.getColumn_info_list(); | |||||
| bizParams.put("column_info_list", columnList); | |||||
| List<AlipayMemberCardModelFieldRule> ruleList = modelRequest.getField_rule_list(); | |||||
| bizParams.put("field_rule_list", ruleList); | |||||
| AlipayOpenApiGenericResponse response = Factory.Util.Generic().execute( | |||||
| "alipay.marketing.card.template.create", textParams, bizParams); | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * https://opendocs.alipay.com/apis/api_5/alipay.marketing.card.formtemplate.set | |||||
| * 会员卡开卡表单模板配置 | |||||
| * @throws Exception | |||||
| */ | |||||
| public static AlipayOpenApiGenericResponse setMemberCardModelConfig(Config config,String appAuthToken,String templateId,String[] requiredFields,String[] optionalFields) throws Exception { | |||||
| Factory.setOptions(config); | |||||
| //设置系统参数(OpenAPI中非biz_content里的参数) | |||||
| Map<String, String> textParams = new HashMap<String, String>(); | |||||
| textParams.put("app_auth_token", appAuthToken); | |||||
| //设置业务参数(OpenAPI中biz_content里的参数) | |||||
| Map<String, Object> bizParams = new HashMap<String, Object>(); | |||||
| bizParams.put("template_id", templateId); | |||||
| Map<String, String> extendParams = new HashMap<>(); | |||||
| Map<String,String[]> requireds = new HashMap<String,String[]>(); | |||||
| requireds.put("common_fields", requiredFields); | |||||
| extendParams.put("required", JSON.toJSONString(requireds)); | |||||
| if (null != optionalFields) { | |||||
| Map<String,String[]> optional = new HashMap<String,String[]>(); | |||||
| optional.put("common_fields", optionalFields); | |||||
| extendParams.put("optional", JSON.toJSONString(optional)); | |||||
| } | |||||
| bizParams.put("fields", extendParams); | |||||
| AlipayOpenApiGenericResponse response = Factory.Util.Generic().execute( | |||||
| "alipay.marketing.card.formtemplate.set", textParams, bizParams); | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * https://opendocs.alipay.com/apis/api_5/alipay.marketing.card.activateurl.apply | |||||
| * 获取会员卡领卡投放链接 | |||||
| * @param callback为子应用回调地址,非ISV应用。 必须跟子应用的后台回调弟子配置一致。 | |||||
| */ | |||||
| public static AlipayOpenApiGenericResponse getMemberCardUrl(Config config,String appAuthToken,String templateId,String exparam,String callback) throws Exception { | |||||
| Factory.setOptions(config); | |||||
| //设置系统参数(OpenAPI中非biz_content里的参数) | |||||
| Map<String, String> textParams = new HashMap<String, String>(); | |||||
| textParams.put("app_auth_token", appAuthToken); | |||||
| //设置业务参数(OpenAPI中biz_content里的参数) | |||||
| Map<String, Object> bizParams = new HashMap<String, Object>(); | |||||
| bizParams.put("template_id", templateId); | |||||
| bizParams.put("out_string", exparam); | |||||
| bizParams.put("callback", callback); | |||||
| AlipayOpenApiGenericResponse response = Factory.Util.Generic().execute( | |||||
| "alipay.marketing.card.activateurl.apply", textParams, bizParams); | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * https://opendocs.alipay.com/apis/api_9/alipay.system.oauth.token | |||||
| * 会员授权,换取授权访问令牌 | |||||
| * @return | |||||
| * @throws Exception | |||||
| */ | |||||
| public static AlipayOpenApiGenericResponse queryUserAuthData(Config config,String appAuthToken,String authCode) throws Exception { | |||||
| Factory.setOptions(config); | |||||
| //设置系统参数(OpenAPI中非biz_content里的参数) | |||||
| Map<String, String> textParams = new HashMap<String, String>(); | |||||
| textParams.put("app_auth_token", appAuthToken); | |||||
| textParams.put("grant_type", "authorization_code"); | |||||
| textParams.put("code", authCode); | |||||
| AlipayOpenApiGenericResponse response = Factory.Util.Generic().execute( | |||||
| "alipay.system.oauth.token", textParams, null); | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * https://opendocs.alipay.com/apis/api_5/alipay.marketing.card.activateform.query | |||||
| * 查询用户提交的会员卡表单信息 | |||||
| * @return | |||||
| * @throws Exception | |||||
| */ | |||||
| public static AlipayOpenApiGenericResponse queryUserFormData(Config config,String appAuthToken,String authToken,String templateId,String requestId) throws Exception { | |||||
| Factory.setOptions(config); | |||||
| //设置系统参数(OpenAPI中非biz_content里的参数) | |||||
| Map<String, String> textParams = new HashMap<String, String>(); | |||||
| textParams.put("app_auth_token", appAuthToken); | |||||
| textParams.put("auth_token", authToken); | |||||
| //设置业务参数(OpenAPI中biz_content里的参数) | |||||
| Map<String, Object> bizParams = new HashMap<String, Object>(); | |||||
| bizParams.put("biz_type", "MEMBER_CARD"); | |||||
| bizParams.put("template_id", templateId); | |||||
| bizParams.put("request_id", requestId); | |||||
| AlipayOpenApiGenericResponse response = Factory.Util.Generic().execute( | |||||
| "alipay.marketing.card.activateform.query", textParams, bizParams); | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * https://opendocs.alipay.com/apis/api_5/alipay.marketing.card.open | |||||
| * 会员卡开卡 | |||||
| * @return | |||||
| * @throws Exception | |||||
| */ | |||||
| public static AlipayOpenApiGenericResponse openCard(Config config,String appAuthToken,String authToken,String templateId,String userId) throws Exception { | |||||
| Factory.setOptions(config); | |||||
| //设置系统参数(OpenAPI中非biz_content里的参数) | |||||
| Map<String, String> textParams = new HashMap<String, String>(); | |||||
| textParams.put("app_auth_token", appAuthToken); | |||||
| textParams.put("auth_token", authToken); | |||||
| //设置业务参数(OpenAPI中biz_content里的参数) | |||||
| Map<String, Object> bizParams = new HashMap<String, Object>(); | |||||
| IdWorker idWorker = IdWorker.get(); | |||||
| bizParams.put("out_serial_no", String.valueOf(idWorker.nextId())); | |||||
| bizParams.put("card_template_id", templateId); | |||||
| Map<String,String> userInfoMap = new HashMap<String,String>(); | |||||
| userInfoMap.put("user_uni_id", userId); | |||||
| userInfoMap.put("user_uni_id_type", "UID"); | |||||
| bizParams.put("card_user_info", userInfoMap); | |||||
| Map<String,Object> extInfoMap = new HashMap<String,Object>(); | |||||
| extInfoMap.put("open_date", new Date()); | |||||
| 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); | |||||
| AlipayOpenApiGenericResponse response = Factory.Util.Generic().execute( | |||||
| "alipay.marketing.card.open", textParams, bizParams); | |||||
| return response; | |||||
| } | |||||
| /** | |||||
| * 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 | |||||
| * @throws Exception | |||||
| */ | |||||
| public static AlipayOpenApiGenericResponse topicSubscribe(Config config,String authToken,String authType,String topic,String type,String tag) throws Exception { | |||||
| Factory.setOptions(config); | |||||
| //设置系统参数(OpenAPI中非biz_content里的参数) | |||||
| //Map<String, String> textParams = new HashMap<String, String>(); | |||||
| //textParams.put("app_auth_token", appAuthToken); | |||||
| //设置业务参数(OpenAPI中biz_content里的参数) | |||||
| Map<String, Object> bizParams = new HashMap<String, Object>(); | |||||
| bizParams.put("auth_token", authToken); | |||||
| bizParams.put("auth_type", authType); | |||||
| bizParams.put("topic", topic); | |||||
| bizParams.put("comm_type", type); | |||||
| if (!StringUtils.isBlank(tag)) { | |||||
| bizParams.put("tag",tag); | |||||
| } | |||||
| AlipayOpenApiGenericResponse response = Factory.Util.Generic().execute( | |||||
| "alipay.open.app.message.topic.subscribe", null, bizParams); | |||||
| return response; | |||||
| } | |||||
| } | |||||
| @@ -1,37 +0,0 @@ | |||||
| package com.iformall.service.pay.alipay.api.enums; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| public enum EnumMemberCardConfig { | |||||
| OPEN_FORM_FIELD_MOBILE("OPEN_FORM_FIELD_MOBILE", "手机号"), | |||||
| OPEN_FORM_FIELD_GENDER("OPEN_FORM_FIELD_GENDER", "性别"), | |||||
| OPEN_FORM_FIELD_NAME("OPEN_FORM_FIELD_NAME", "姓名"); | |||||
| public static EnumMemberCardConfig getEnum(String code) { | |||||
| for (EnumMemberCardConfig value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private String code; | |||||
| private String message; | |||||
| EnumMemberCardConfig(String code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public String getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -1,21 +0,0 @@ | |||||
| package com.iformall.service.pay.alipay.api.reqEntity; | |||||
| import com.aliyun.tea.TeaModel; | |||||
| public class AlipayMemberCardModelColumn{ | |||||
| private String code;//标准栏位:行为由支付宝统一定,同时已经分配标准Code | |||||
| private String title;//栏目的标题 | |||||
| public String getCode() { | |||||
| return code; | |||||
| } | |||||
| public void setCode(String code) { | |||||
| this.code = code; | |||||
| } | |||||
| public String getTitle() { | |||||
| return title; | |||||
| } | |||||
| public void setTitle(String title) { | |||||
| this.title = title; | |||||
| } | |||||
| } | |||||
| @@ -1,28 +0,0 @@ | |||||
| package com.iformall.service.pay.alipay.api.reqEntity; | |||||
| import com.aliyun.tea.TeaModel; | |||||
| public class AlipayMemberCardModelFieldRule{ | |||||
| private String field_name;//字段名称,现在支持如下几个Key(暂不支持自定义) | |||||
| private String rule_name;//规则名 | |||||
| private String rule_value;//根据rule_name,采取相应取值策略 | |||||
| public String getField_name() { | |||||
| return field_name; | |||||
| } | |||||
| public void setField_name(String field_name) { | |||||
| this.field_name = field_name; | |||||
| } | |||||
| public String getRule_name() { | |||||
| return rule_name; | |||||
| } | |||||
| public void setRule_name(String rule_name) { | |||||
| this.rule_name = rule_name; | |||||
| } | |||||
| public String getRule_value() { | |||||
| return rule_value; | |||||
| } | |||||
| public void setRule_value(String rule_value) { | |||||
| this.rule_value = rule_value; | |||||
| } | |||||
| } | |||||
| @@ -1,52 +0,0 @@ | |||||
| package com.iformall.service.pay.alipay.api.reqEntity; | |||||
| import java.util.List; | |||||
| import com.aliyun.tea.NameInMap; | |||||
| import com.aliyun.tea.Validation; | |||||
| public class AlipayMemberCardModelRequest{ | |||||
| private String card_type="OUT_MEMBER_CARD";//卡类型。可选类型如下:OUT_MEMBER_CARD:外部权益卡 | |||||
| private String biz_no_suffix_len ="8";//业务卡号后缀的长度,取值范围为[8,32] | |||||
| private String write_off_type = "qrcode";//卡包详情页面中展现出的卡码 | |||||
| private AlipayMemberCardModelStyle template_style_info;//模板样式信息 | |||||
| private List<AlipayMemberCardModelColumn> column_info_list;//栏位信息 | |||||
| private List<AlipayMemberCardModelFieldRule> field_rule_list;//字段规则列表,会员卡开卡过程中,会员卡信息的生成规则 | |||||
| public String getCard_type() { | |||||
| return card_type; | |||||
| } | |||||
| public void setCard_type(String card_type) { | |||||
| this.card_type = card_type; | |||||
| } | |||||
| public String getBiz_no_suffix_len() { | |||||
| return biz_no_suffix_len; | |||||
| } | |||||
| public void setBiz_no_suffix_len(String biz_no_suffix_len) { | |||||
| this.biz_no_suffix_len = biz_no_suffix_len; | |||||
| } | |||||
| public String getWrite_off_type() { | |||||
| return write_off_type; | |||||
| } | |||||
| public void setWrite_off_type(String write_off_type) { | |||||
| this.write_off_type = write_off_type; | |||||
| } | |||||
| public AlipayMemberCardModelStyle getTemplate_style_info() { | |||||
| return template_style_info; | |||||
| } | |||||
| public void setTemplate_style_info(AlipayMemberCardModelStyle template_style_info) { | |||||
| this.template_style_info = template_style_info; | |||||
| } | |||||
| public List<AlipayMemberCardModelColumn> getColumn_info_list() { | |||||
| return column_info_list; | |||||
| } | |||||
| public void setColumn_info_list(List<AlipayMemberCardModelColumn> column_info_list) { | |||||
| this.column_info_list = column_info_list; | |||||
| } | |||||
| public List<AlipayMemberCardModelFieldRule> getField_rule_list() { | |||||
| return field_rule_list; | |||||
| } | |||||
| public void setField_rule_list(List<AlipayMemberCardModelFieldRule> field_rule_list) { | |||||
| this.field_rule_list = field_rule_list; | |||||
| } | |||||
| } | |||||
| @@ -1,35 +0,0 @@ | |||||
| package com.iformall.service.pay.alipay.api.reqEntity; | |||||
| import com.aliyun.tea.TeaModel; | |||||
| public class AlipayMemberCardModelStyle{ | |||||
| private String card_show_name;//钱包端显示名称(字符串长度) | |||||
| private String logo_id;//logo的图片ID | |||||
| private String background_id;//背景图片Id | |||||
| private String bg_color="rgb(55,112,179)";//字体颜色(非背景色),只影响卡详情中部信息区域字体颜色 | |||||
| public String getCard_show_name() { | |||||
| return card_show_name; | |||||
| } | |||||
| public void setCard_show_name(String card_show_name) { | |||||
| this.card_show_name = card_show_name; | |||||
| } | |||||
| public String getLogo_id() { | |||||
| return logo_id; | |||||
| } | |||||
| public void setLogo_id(String logo_id) { | |||||
| this.logo_id = logo_id; | |||||
| } | |||||
| public String getBackground_id() { | |||||
| return background_id; | |||||
| } | |||||
| public void setBackground_id(String background_id) { | |||||
| this.background_id = background_id; | |||||
| } | |||||
| public String getBg_color() { | |||||
| return bg_color; | |||||
| } | |||||
| public void setBg_color(String bg_color) { | |||||
| this.bg_color = bg_color; | |||||
| } | |||||
| } | |||||
| @@ -1,10 +0,0 @@ | |||||
| package com.iformall.service.pay.alipay.api.result; | |||||
| import lombok.Data; | |||||
| @Data | |||||
| public class UserAuthData { | |||||
| private String userId; | |||||
| private String accessToken; | |||||
| } | |||||
| @@ -1,23 +0,0 @@ | |||||
| package com.iformall.service.pay.alipay.config; | |||||
| import lombok.Data; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| import org.springframework.context.annotation.Configuration; | |||||
| import org.springframework.stereotype.Component; | |||||
| /** | |||||
| * alipay 配置 | |||||
| */ | |||||
| @Data | |||||
| @Configuration | |||||
| @ConfigurationProperties(prefix = "alipay.open") | |||||
| public class AliPayConfig { | |||||
| private String appId; | |||||
| private String appPrivateKey; | |||||
| private String appPublicKeyCertPath; | |||||
| private String alipayCertPath; | |||||
| private String alipayRootCertPath; | |||||
| private String callback; | |||||
| } | |||||
| @@ -0,0 +1,93 @@ | |||||
| package com.iformall.service.pay.service.pay.ali; | |||||
| import com.alibaba.fastjson.JSON; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.alipay.api.AlipayClient; | |||||
| import com.alipay.api.request.AlipayTradeQueryRequest; | |||||
| import com.alipay.api.response.AlipayTradeQueryResponse; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.domain.po.ProductOrderPay; | |||||
| import com.iformall.domain.po.WxAppinfo; | |||||
| import com.iformall.domain.po.WxPayAccount; | |||||
| import com.iformall.domain.po.WxPayOrder; | |||||
| import com.iformall.enums.EnumPayOrderStatus; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||||
| import com.iformall.utils.MaUtil; | |||||
| import lombok.extern.slf4j.Slf4j; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import java.util.HashMap; | |||||
| import java.util.Map; | |||||
| @Slf4j | |||||
| public class BaseAliPayAdapterService { | |||||
| @Autowired | |||||
| protected MaUtil maUtil; | |||||
| /** | |||||
| * 做为支付的扩展数据 | |||||
| * @param | |||||
| * @return | |||||
| */ | |||||
| protected String getCallbackData(WxPayOrder record) { | |||||
| Map<String,Object> map = new HashMap<>(); | |||||
| map.put("composeOrderId",record.getOrderId()); | |||||
| map.put("tenantId",record.getTenantId()); | |||||
| return JSON.toJSONString(map); | |||||
| } | |||||
| protected PayQueryAdapterResult queryPayStatus(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) | |||||
| throws Exception { | |||||
| AlipayClient alipayClient = maUtil.getAliPayClient(appInfo, payAccount); | |||||
| AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); | |||||
| JSONObject bizContent = new JSONObject(); | |||||
| //商户订单号,商家自定义,保持唯一性 | |||||
| bizContent.put("out_trade_no", orderPay.getOrderNumber()); | |||||
| request.setBizContent(bizContent.toString()); | |||||
| AlipayTradeQueryResponse response = alipayClient.execute(request); | |||||
| if(response.isSuccess()){ | |||||
| if("10000".equals(response.getCode())){ | |||||
| PayQueryAdapterResult result = new PayQueryAdapterResult(); | |||||
| result.setCode(getPayStatusFrom(response.getTradeStatus())); | |||||
| result.setTransactionId(response.getTradeNo()); | |||||
| return result; | |||||
| } | |||||
| if("ACQ.TRADE_NOT_EXIST".equals(response.getSubCode())){ | |||||
| PayQueryAdapterResult result = new PayQueryAdapterResult(); | |||||
| result.setCode(EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||||
| result.setMsg(EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getMessage()); | |||||
| return result; | |||||
| } | |||||
| } | |||||
| throw new MallinkException(ErrorCode.PAY_ORDER_QUERY_ERROR); | |||||
| } | |||||
| private int getPayStatusFrom(String trade_status){ | |||||
| if("WAIT_BUYER_PAY".equals(trade_status)){ | |||||
| return EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode(); | |||||
| }else if("TRADE_CLOSED".equals(trade_status)){ | |||||
| return EnumPayOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode(); | |||||
| }else if("TRADE_SUCCESS".equals(trade_status)){ | |||||
| return EnumPayOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode(); | |||||
| }else if("TRADE_FINISHED".equals(trade_status)){ | |||||
| return EnumPayOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode(); | |||||
| } | |||||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "订单查询支付宝支付状态失败"+trade_status); | |||||
| } | |||||
| protected int queryPayStatus(PayQueryAdapterResult statusObject, String orderOutNo) throws Exception { | |||||
| return statusObject.getCode(); | |||||
| } | |||||
| protected PayAdapterResult closeOrder(WxAppinfo appInfo, WxPayOrder record,WxPayAccount payAccount) { | |||||
| return new PayAdapterResult(true, "success", null, null); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,145 @@ | |||||
| package com.iformall.service.pay.service.pay.ali.page; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.alipay.api.AlipayClient; | |||||
| import com.alipay.api.request.AlipayTradePagePayRequest; | |||||
| import com.alipay.api.response.AlipayTradePagePayResponse; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.enums.*; | |||||
| import com.iformall.service.order.OrderFactory; | |||||
| import com.iformall.service.order.entity.WxComposeOrder; | |||||
| import com.iformall.service.pay.entity.PayExtraParam; | |||||
| import com.iformall.service.pay.service.pay.CDrivingPayService; | |||||
| import com.iformall.service.pay.service.pay.ali.BaseAliPayAdapterService; | |||||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||||
| import com.iformall.utils.DateUtils; | |||||
| import com.iformall.utils.MaUtil; | |||||
| import lombok.extern.slf4j.Slf4j; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.io.File; | |||||
| import java.util.*; | |||||
| @Slf4j | |||||
| @Service | |||||
| public class AliPagePayAdapterService extends BaseAliPayAdapterService implements CDrivingPayService{ | |||||
| @Autowired | |||||
| OrderFactory orderFactory; | |||||
| @Autowired | |||||
| private MaUtil maUtil; | |||||
| @Override | |||||
| public PayAdapterResult pay(WxPayAccount payAccount,WxPayOrder record,WxComposeOrder composeOrder,List<WxOrder> childOrders, | |||||
| String productName,EnumPayShare isShare,WxAppinfo appInfo,Date currentDate, PayExtraParam params) throws Exception { | |||||
| return null; | |||||
| } | |||||
| @Override | |||||
| public PayAdapterResult createPay(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||||
| AlipayClient alipayClient = maUtil.getAliPayClient(appInfo, payAccount); | |||||
| AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); | |||||
| //异步接收地址,仅支持http/https,公网可访问 | |||||
| request.setNotifyUrl(payAccount.getNotifyUrl() + "/aliNotify"); | |||||
| //同步跳转地址,仅支持http/https | |||||
| // request.setReturnUrl(""); | |||||
| /******必传参数******/ | |||||
| JSONObject bizContent = new JSONObject(); | |||||
| //商户订单号,商家自定义,保持唯一性 | |||||
| bizContent.put("out_trade_no", orderPay.getOrderNumber()); | |||||
| //支付金额,最小值0.01元 | |||||
| bizContent.put("total_amount", orderPay.getPayAmountStr()); | |||||
| //订单标题,不可使用特殊符号 | |||||
| bizContent.put("subject", orderPay.getOrderDetail()); | |||||
| //电脑网站支付场景固定传值FAST_INSTANT_TRADE_PAY | |||||
| bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY"); | |||||
| bizContent.put("qr_pay_mode",1); | |||||
| String after15 = DateUtils.date2String(DateUtils.getSecondsTimeAfter(15 * 60, new Date())); | |||||
| bizContent.put("time_expire", after15); | |||||
| request.setBizContent(bizContent.toString()); | |||||
| AlipayTradePagePayResponse response = alipayClient.pageExecute(request); | |||||
| PayAdapterResult par = new PayAdapterResult(); | |||||
| if(response.isSuccess()){ | |||||
| if("10000".equals(response.getCode())){ | |||||
| par.setSuccess(true); | |||||
| par.setTransactionId(response.getTradeNo()); | |||||
| par.setData(response); | |||||
| }else{ | |||||
| par.setSuccess(false); | |||||
| par.setMsg(response.getMsg()); | |||||
| } | |||||
| } else { | |||||
| par.setSuccess(false); | |||||
| } | |||||
| return par; | |||||
| } | |||||
| @Override | |||||
| public PayQueryAdapterResult queryPayStatus(WxPayOrder oldRecord, WxAppinfo appInfo, | |||||
| WxPayAccount payAccount) throws Exception { | |||||
| return null; | |||||
| } | |||||
| @Override | |||||
| public PayQueryAdapterResult queryPayStatus(ProductOrderPay orderPay, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { | |||||
| return super.queryPayStatus(orderPay,appInfo,payAccount); | |||||
| } | |||||
| @Override | |||||
| public int queryPayStatus(PayQueryAdapterResult statusObject, String orderOutNo) throws Exception { | |||||
| return 0; | |||||
| } | |||||
| @Override | |||||
| public int queryPayStatusCode(WxPayOrder oldRecord, WxAppinfo appInfo, WxPayAccount payAccount) | |||||
| throws Exception { | |||||
| return 0; | |||||
| } | |||||
| @Override | |||||
| public PayAdapterResult payOrderClose(WxAppinfo appInfo, WxPayOrder record,WxPayAccount payAccount) throws Exception { | |||||
| //todo | |||||
| return super.closeOrder(appInfo, record, payAccount); | |||||
| } | |||||
| @Override | |||||
| public PayAdapterResult payOrderReverse(WxAppinfo appInfo, WxPayOrder record, WxPayAccount payAccount) | |||||
| throws Exception { | |||||
| return null; | |||||
| } | |||||
| @Override | |||||
| public PayAdapterResult payOrderPush(String openId,WxAppinfo appInfo, WxBatchOrder batchOrder,WxPayOrder payOrder) throws Exception { | |||||
| return null; | |||||
| } | |||||
| @Override | |||||
| public File getQrcode(WxAppinfo appinfo,String pageUrl,int type,String sceneParam) throws Exception{ | |||||
| return null; | |||||
| } | |||||
| @Override | |||||
| public String getScheme(WxAppinfo appinfo, String pageUrl, String sceneParam, Long expireTime) throws Exception { | |||||
| return null; | |||||
| } | |||||
| @Override | |||||
| public PayAdapterResult noCreatePay(WxPayOrder record, WxComposeOrder composeOrder, List<WxOrder> childOrders) { | |||||
| return null; | |||||
| } | |||||
| @Override | |||||
| public void sendSubscribeMsg(WxAppinfo appinfo, WxTemplateMsg wxTemplateMsg, String openId, String toPage, Map<String, String> param) throws Exception{ | |||||
| } | |||||
| } | |||||
| @@ -3,9 +3,14 @@ package com.iformall.utils; | |||||
| import cn.binarywang.wx.miniapp.api.WxMaService; | import cn.binarywang.wx.miniapp.api.WxMaService; | ||||
| import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; | import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; | ||||
| import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; | import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; | ||||
| import com.alipay.api.AlipayApiException; | |||||
| import com.alipay.api.AlipayClient; | |||||
| import com.alipay.api.AlipayConfig; | |||||
| import com.alipay.api.DefaultAlipayClient; | |||||
| import com.github.binarywang.wxpay.config.WxPayConfig; | import com.github.binarywang.wxpay.config.WxPayConfig; | ||||
| import com.github.binarywang.wxpay.service.WxPayService; | import com.github.binarywang.wxpay.service.WxPayService; | ||||
| import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; | import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.FmHttpClientBuilder; | import com.iformall.common.FmHttpClientBuilder; | ||||
| import com.iformall.domain.po.WxAppinfo; | import com.iformall.domain.po.WxAppinfo; | ||||
| import com.iformall.domain.po.WxPayAccount; | import com.iformall.domain.po.WxPayAccount; | ||||
| @@ -23,6 +28,7 @@ import com.iformall.douyin.web.api.TtWebService; | |||||
| import com.iformall.douyin.web.api.impl.TtWebServiceImpl; | import com.iformall.douyin.web.api.impl.TtWebServiceImpl; | ||||
| import com.iformall.douyin.web.config.TtWebDefaultConfigImpl; | import com.iformall.douyin.web.config.TtWebDefaultConfigImpl; | ||||
| import com.iformall.douyin.web.enums.TtWebApiBeginEnum; | import com.iformall.douyin.web.enums.TtWebApiBeginEnum; | ||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.mapper.WxAppinfoMapper; | import com.iformall.mapper.WxAppinfoMapper; | ||||
| import com.iformall.service.WxAppinfoService; | import com.iformall.service.WxAppinfoService; | ||||
| import lombok.extern.flogger.Flogger; | import lombok.extern.flogger.Flogger; | ||||
| @@ -56,6 +62,9 @@ public class MaUtil { | |||||
| private static Map<String,TtWebService> webServiceMap = new ConcurrentHashMap<String,TtWebService>(); | private static Map<String,TtWebService> webServiceMap = new ConcurrentHashMap<String,TtWebService>(); | ||||
| private static Map<String,String> webServiceKeyMap = new ConcurrentHashMap<String,String>(); | private static Map<String,String> webServiceKeyMap = new ConcurrentHashMap<String,String>(); | ||||
| private static Map<String,AlipayClient> alipayClientMap = new ConcurrentHashMap<String,AlipayClient>(); | |||||
| private static Map<String,String> alipayClientKeyMap = new ConcurrentHashMap<String,String>(); | |||||
| public WxMaService getWeappService(WxAppinfo appinfo) { | public WxMaService getWeappService(WxAppinfo appinfo) { | ||||
| WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); | WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); | ||||
| @@ -290,4 +299,36 @@ public class MaUtil { | |||||
| } | } | ||||
| return service; | return service; | ||||
| } | } | ||||
| public AlipayClient getAliPayClient(WxAppinfo appinfo, WxPayAccount payAccount) { | |||||
| AlipayConfig alipayConfig = new AlipayConfig(); | |||||
| alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do"); | |||||
| alipayConfig.setAppId(appinfo.getAppId()); | |||||
| alipayConfig.setPrivateKey(appinfo.getSecret()); | |||||
| alipayConfig.setFormat("json"); | |||||
| alipayConfig.setCharset("UTF-8"); | |||||
| alipayConfig.setAlipayPublicKey(payAccount.getMerchantApiKey()); | |||||
| alipayConfig.setSignType("RSA2"); | |||||
| String key = appinfo.getAppId(); | |||||
| AlipayClient alipayClient = alipayClientMap.get(key); | |||||
| if(alipayClient == null){ | |||||
| synchronized("getAliPayClientBlock"+appinfo.getAppId()) { | |||||
| alipayClient = alipayClientMap.get(key); | |||||
| if (null == alipayClient) { | |||||
| try { | |||||
| alipayClient = new DefaultAlipayClient(alipayConfig); | |||||
| alipayClientMap.put(key, alipayClient); | |||||
| } catch (AlipayApiException e) { | |||||
| e.printStackTrace(); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| if(alipayClient == null){ | |||||
| throw new MallinkException(ErrorCode.APP_PLAT_ERROR.getCode(),"获取支付配置失败"); | |||||
| } | |||||
| return alipayClient; | |||||
| } | |||||
| } | } | ||||