支付参数判定重复代码处理
This commit is contained in:
		
							parent
							
								
									0c234e78af
								
							
						
					
					
						commit
						8e1ade5423
					
				| @ -258,9 +258,6 @@ public class WechatPlugin implements Payment { | |||||||
| 
 | 
 | ||||||
|             WechatPaymentSetting setting = wechatPaymentSetting(); |             WechatPaymentSetting setting = wechatPaymentSetting(); | ||||||
|             String appid = setting.getAppId(); |             String appid = setting.getAppId(); | ||||||
|             if (appid == null) { |  | ||||||
|                 throw new ServiceException(ResultCode.WECHAT_PAYMENT_NOT_SETTING); |  | ||||||
|             } |  | ||||||
|             UnifiedOrderModel unifiedOrderModel = new UnifiedOrderModel() |             UnifiedOrderModel unifiedOrderModel = new UnifiedOrderModel() | ||||||
|                     .setAppid(appid) |                     .setAppid(appid) | ||||||
|                     .setMchid(setting.getMchId()) |                     .setMchid(setting.getMchId()) | ||||||
| @ -326,9 +323,6 @@ public class WechatPlugin implements Payment { | |||||||
|             WechatPaymentSetting setting = wechatPaymentSetting(); |             WechatPaymentSetting setting = wechatPaymentSetting(); | ||||||
| 
 | 
 | ||||||
|             String appid = setting.getServiceAppId(); |             String appid = setting.getServiceAppId(); | ||||||
|             if (appid == null) { |  | ||||||
|                 throw new ServiceException(ResultCode.WECHAT_PAYMENT_NOT_SETTING); |  | ||||||
|             } |  | ||||||
|             UnifiedOrderModel unifiedOrderModel = new UnifiedOrderModel() |             UnifiedOrderModel unifiedOrderModel = new UnifiedOrderModel() | ||||||
|                     .setAppid(appid) |                     .setAppid(appid) | ||||||
|                     .setMchid(setting.getMchId()) |                     .setMchid(setting.getMchId()) | ||||||
| @ -397,10 +391,6 @@ public class WechatPlugin implements Payment { | |||||||
|             //微信小程序,appid 需要单独获取,这里读取了联合登陆配置的appid ,实际场景小程序自动登录,所以这个appid是最为保险的做法 |             //微信小程序,appid 需要单独获取,这里读取了联合登陆配置的appid ,实际场景小程序自动登录,所以这个appid是最为保险的做法 | ||||||
|             //如果有2开需求,这里需要调整,修改这个appid的获取途径即可 |             //如果有2开需求,这里需要调整,修改这个appid的获取途径即可 | ||||||
|             String appid = wechatPaymentSetting().getMpAppId(); |             String appid = wechatPaymentSetting().getMpAppId(); | ||||||
|             if (appid == null) { |  | ||||||
|                 throw new ServiceException(ResultCode.WECHAT_PAYMENT_NOT_SETTING); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             String attach = URLEncoder.createDefault().encode(JSONUtil.toJsonStr(payParam), StandardCharsets.UTF_8); |             String attach = URLEncoder.createDefault().encode(JSONUtil.toJsonStr(payParam), StandardCharsets.UTF_8); | ||||||
| 
 | 
 | ||||||
|             WechatPaymentSetting setting = wechatPaymentSetting(); |             WechatPaymentSetting setting = wechatPaymentSetting(); | ||||||
|  | |||||||
| @ -1,5 +1,8 @@ | |||||||
| package cn.lili.modules.system.entity.dto.payment; | package cn.lili.modules.system.entity.dto.payment; | ||||||
| 
 | 
 | ||||||
|  | import cn.lili.common.enums.ResultCode; | ||||||
|  | import cn.lili.common.exception.ServiceException; | ||||||
|  | import com.alibaba.druid.util.StringUtils; | ||||||
| import lombok.Data; | import lombok.Data; | ||||||
| import lombok.experimental.Accessors; | import lombok.experimental.Accessors; | ||||||
| 
 | 
 | ||||||
| @ -14,7 +17,7 @@ import lombok.experimental.Accessors; | |||||||
| public class WechatPaymentSetting { | public class WechatPaymentSetting { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      *  APP应用id |      * APP应用id | ||||||
|      */ |      */ | ||||||
|     private String appId; |     private String appId; | ||||||
|     /** |     /** | ||||||
| @ -49,4 +52,26 @@ public class WechatPaymentSetting { | |||||||
|      * apiv3私钥 |      * apiv3私钥 | ||||||
|      */ |      */ | ||||||
|     private String apiKey3; |     private String apiKey3; | ||||||
|  | 
 | ||||||
|  |     public String getAppId() { | ||||||
|  | 
 | ||||||
|  |         if (StringUtils.isEmpty(appId)) { | ||||||
|  |             throw new ServiceException(ResultCode.WECHAT_PAYMENT_NOT_SETTING); | ||||||
|  |         } | ||||||
|  |         return appId; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public String getMpAppId() { | ||||||
|  |         if (StringUtils.isEmpty(mpAppId)) { | ||||||
|  |             throw new ServiceException(ResultCode.WECHAT_PAYMENT_NOT_SETTING); | ||||||
|  |         } | ||||||
|  |         return mpAppId; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public String getServiceAppId() { | ||||||
|  |         if (StringUtils.isEmpty(serviceAppId)) { | ||||||
|  |             throw new ServiceException(ResultCode.WECHAT_PAYMENT_NOT_SETTING); | ||||||
|  |         } | ||||||
|  |         return serviceAppId; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Chopper
						Chopper