| | |
| | | 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 cc.mrbird.febs.vip.service.IMallVipConfigService; |
| | | 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 |
| | | * @date 2021-09-27 |
| | | **/ |
| | | @Slf4j |
| | | @SpringBootTest |
| | | public class PayTest { |
| | | |
| | | |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | @Resource |
| | | RestTemplate restTemplate; |
| | | @Test |
| | | public void aliPay(){ |
| | | |
| | | String appId = "wx16d0b75302b360d4"; |
| | | String appSecret = "a2887cd622ed981d2e04d724d29d7454"; |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | @Autowired |
| | | private IMallVipConfigService mallVipConfigService; |
| | | |
| | | @Test |
| | | public void test() { |
| | | mallVipConfigService.findConfigList(); |
| | | } |
| | | } |
| | | //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 cc.mrbird.febs.vip.service.IMallVipConfigService; |
| | | //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 |
| | | // * @date 2021-09-27 |
| | | // **/ |
| | | //@Slf4j |
| | | //@SpringBootTest |
| | | //public class PayTest { |
| | | // |
| | | // |
| | | // @Autowired |
| | | // private RedisUtils redisUtils; |
| | | // @Resource |
| | | // RestTemplate restTemplate; |
| | | // @Test |
| | | // public void aliPay(){ |
| | | // |
| | | // String appId = "wx16d0b75302b360d4"; |
| | | // String appSecret = "a2887cd622ed981d2e04d724d29d7454"; |
| | | // 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); |
| | | // } |
| | | // } |
| | | // |
| | | // @Autowired |
| | | // private IMallVipConfigService mallVipConfigService; |
| | | // |
| | | // @Test |
| | | // public void test() { |
| | | // mallVipConfigService.findConfigList(); |
| | | // } |
| | | //} |