java110
2022-05-24 3721d9e4c1f79b7b38d89db3a73c62135640be64
service-acct/src/main/java/com/java110/acct/smo/impl/QrCodeAliPaymentAdapt.java
@@ -9,14 +9,23 @@
import com.alipay.api.response.AlipayTradePayResponse;
import com.alipay.api.response.AlipayTradeQueryResponse;
import com.java110.acct.smo.IQrCodePaymentSMO;
import com.java110.core.factory.CommunitySettingFactory;
import com.java110.core.log.LoggerFactory;
import com.java110.utils.cache.MappingCache;
import com.java110.utils.constant.WechatConstant;
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;
/**
 * 阿里支付
 */
@Service
public class QrCodeAliPaymentAdapt implements IQrCodePaymentSMO {
    private static Logger logger = LoggerFactory.getLogger(QrCodeAliPaymentAdapt.class);
    /**
     * APP_ID 应用id
     */
@@ -38,12 +47,16 @@
    /**
     * (沙箱)网关
     */
    public final static String GETEWAY_URL = "https://openapi.alipaydev.com/gateway.do";
    public final static String GETEWAY_URL = "https://openapi.alipay.com/gateway.do";
    /**
     * 格式化
     */
    public final static String FORMAT = "json";
    /**
     * 格式化
     */
    public final static String APP_AUTH_TOKEN = "APP_AUTH_TOKEN";
    /**
     * 签名类型
@@ -54,10 +67,14 @@
    public ResultVo pay(String communityId, String orderNum, double money, String authCode, String feeName) throws Exception {
        String systemName = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.PAY_GOOD_NAME);
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",
                "app_id",
                "your private_key", "json", "GBK", "alipay_public_key", "RSA2");
        AlipayClient alipayClient = new DefaultAlipayClient(GETEWAY_URL,
                CommunitySettingFactory.getValue(communityId, "APP_ID"),
                CommunitySettingFactory.getRemark(communityId, "APP_PRIVATE_KEY"),
                "json", "UTF-8", CommunitySettingFactory.getRemark(communityId, "ALIPAY_PUBLIC_KEY"), "RSA2");
        AlipayTradePayRequest request = new AlipayTradePayRequest();
        if (!StringUtil.isEmpty(CommunitySettingFactory.getValue(communityId, APP_AUTH_TOKEN))) {
            request.putOtherTextParam("app_auth_token", CommunitySettingFactory.getValue(communityId, APP_AUTH_TOKEN));
        }
        JSONObject bizContent = new JSONObject();
        bizContent.put("out_trade_no", orderNum);
        bizContent.put("total_amount", money);
@@ -66,26 +83,34 @@
        bizContent.put("auth_code", authCode);
        request.setBizContent(bizContent.toString());
        AlipayTradePayResponse response = alipayClient.execute(request);
        if (response.isSuccess()) {
        logger.debug("支付宝返回:" + JSONObject.toJSONString(response));
        if ("10000".equals(response.getCode()) && response.isSuccess()) {
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }
        if (response.isSuccess()) {
        if ("10000".equals(response.getCode()) && response.isSuccess()) {
            return new ResultVo(ResultVo.CODE_OK, "成功");
        } else {
            return new ResultVo(ResultVo.CODE_ERROR, response.getSubMsg());
            return new ResultVo(ResultVo.CODE_ERROR, StringUtil.isEmpty(response.getSubMsg())?"等待用户支付":response.getSubMsg());
        }
    }
    @Override
    public ResultVo checkPayFinish(String communityId, String orderNum) {
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", "app_id", "your private_key", "json", "GBK", "alipay_public_key", "RSA2");
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",
                CommunitySettingFactory.getValue(communityId, "APP_ID"),
                CommunitySettingFactory.getRemark(communityId, "APP_PRIVATE_KEY"),
                "json", "UTF-8",
                CommunitySettingFactory.getRemark(communityId, "ALIPAY_PUBLIC_KEY"), "RSA2");
        AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
        if (!StringUtil.isEmpty(CommunitySettingFactory.getValue(communityId, APP_AUTH_TOKEN))) {
            request.putOtherTextParam("app_auth_token", CommunitySettingFactory.getValue(communityId, APP_AUTH_TOKEN));
        }
        request.setBizContent("{" +
                "  \"out_trade_no\":\"20150320010101001\"," +
                "  \"trade_no\":\"2014112611001004680 073956707\"," +
                "  \"out_trade_no\":\"" + orderNum + "\"," +
                "  \"trade_no\":\"\"," +
                "  \"query_options\":[" +
                "    \"trade_settle_info\"" +
                "  ]" +
@@ -96,7 +121,7 @@
        } catch (AlipayApiException e) {
            return new ResultVo(ResultVo.CODE_ERROR, "查询失败" + e.getErrMsg());
        }
        logger.debug("支付宝返回:" + JSONObject.toJSONString(response));
        if (!"10000".equals(response.getCode())) {
            return new ResultVo(ResultVo.CODE_ERROR, response.getMsg());
        }