| | |
| | | package cc.mrbird.febs; |
| | | |
| | | import cc.mrbird.febs.common.properties.XcxProperties; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.common.utils.SpringContextHolder; |
| | | import cc.mrbird.febs.pay.util.WechatConfigure; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alipay.api.AlipayApiException; |
| | | import com.alipay.api.domain.AlipayTradeAppPayModel; |
| | | import com.alipay.api.response.AlipayTradeAppPayResponse; |
| | | import com.baomidou.mybatisplus.extension.exceptions.ApiException; |
| | | import com.ijpay.alipay.AliPayApi; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | @SpringBootTest |
| | | public class PayTest { |
| | | |
| | | |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | @Resource |
| | | RestTemplate restTemplate; |
| | | @Test |
| | | public void aliPay() throws AlipayApiException { |
| | | AlipayTradeAppPayModel model = new AlipayTradeAppPayModel(); |
| | | model.setBody("这是测试用"); |
| | | model.setSubject("支付测试用的"); |
| | | model.setOutTradeNo("2021092712215802974"); |
| | | model.setTimeoutExpress("15m"); |
| | | model.setTotalAmount("0.01"); |
| | | model.setPassbackParams("callback params"); |
| | | model.setProductCode("QUICK_MSECURITY_PAY"); |
| | | AlipayTradeAppPayResponse resp = AliPayApi.appPayToResponse(model, ""); |
| | | log.info("=====>>>{}", JSONObject.toJSONString(resp)); |
| | | public void aliPay(){ |
| | | |
| | | String appId = "wxfb1acf504eb9d058"; |
| | | String appSecret = "7ee226a964b1be7cfb96f5e0dc739c44"; |
| | | String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appId + "&secret=" + appSecret; |
| | | String jsonStr = restTemplate.getForObject(url, String.class); |
| | | |
| | | /** |
| | | * 返回结果 |
| | | * {"access_token":"ACCESS_TOKEN","expires_in":7200} |
| | | */ |
| | | if (!jsonStr.contains("access_token")) { |
| | | System.out.println("获取微信access_token失败"); |
| | | } |
| | | |
| | | String accessTokenKey = WechatConfigure.WX_ACCESS_TOKEN_REDIS_KEY; |
| | | JSONObject jsonObject = JSONObject.parseObject(jsonStr); |
| | | String accessToken = jsonObject.getString(accessTokenKey); |
| | | if (StrUtil.isEmpty(accessToken)) { |
| | | log.error("获取access token失败: {}" , jsonObject.getString("errmsg")); |
| | | throw new ApiException("获取access token失败"); |
| | | } else { |
| | | log.info("wx access_token : {}",accessToken); |
| | | redisUtils.set(accessTokenKey,accessToken); |
| | | } |
| | | } |
| | | } |