New file |
| | |
| | | package com.ks.vip.util; |
| | | |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.yeshi.utils.alipay.AlipayH5PayUtil; |
| | | import org.yeshi.utils.entity.alipay.AlipayAppInfo; |
| | | import org.yeshi.utils.entity.wx.WXAPPInfo; |
| | | import org.yeshi.utils.entity.wx.WXPlaceOrderParams; |
| | | import org.yeshi.utils.wx.WXPayV3Util; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.util.Properties; |
| | | |
| | | public class PayUtil { |
| | | |
| | | |
| | | public static AlipayAppInfo getAlipayApp() { |
| | | try { |
| | | Properties properties = new Properties(); |
| | | properties.load(PayUtil.class.getClassLoader().getResourceAsStream("alipay.properties")); |
| | | String appId = properties.getProperty("app_id"); |
| | | String privateKey = properties.getProperty("private_key"); |
| | | String publicKey = properties.getProperty("alipay_public_key"); |
| | | AlipayAppInfo appInfo = new AlipayAppInfo(appId, privateKey, publicKey); |
| | | return appInfo; |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 获取微信app |
| | | * |
| | | * @return |
| | | */ |
| | | |
| | | public static WXAPPInfo getWXAPP() { |
| | | String privateKey = ""; |
| | | try { |
| | | String content = IOUtils.toString(PayUtil.class.getClassLoader().getResourceAsStream("wx/apiclient_key.pem")); |
| | | privateKey = content.replace("-----BEGIN PRIVATE KEY-----", "") |
| | | .replace("-----END PRIVATE KEY-----", "") |
| | | .replaceAll("\\s+", ""); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | |
| | | Properties properties = new Properties(); |
| | | try { |
| | | properties.load(PayUtil.class.getClassLoader().getResourceAsStream("wxpay.properties")); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | String appId = properties.getProperty("app_id"); |
| | | String mchId = properties.getProperty("mch_id"); |
| | | String mchSerialNo = properties.getProperty("mch_serial_no"); |
| | | String apiV3Key = properties.getProperty("api_v3_key"); |
| | | |
| | | WXAPPInfo app = new WXAPPInfo(appId, mchId, mchSerialNo, privateKey, apiV3Key); |
| | | |
| | | return app; |
| | | } |
| | | |
| | | /** |
| | | * 获取会员充值支付宝支付表单 |
| | | * |
| | | * @param orderNo |
| | | * @param money |
| | | * @return |
| | | */ |
| | | public static String getVipChargeAlipayForm(String id, OrderType orderType, String orderNo, BigDecimal money) { |
| | | try { |
| | | String goodsTitle = "影视大全会员充值"; |
| | | if (orderType == OrderType.video) { |
| | | goodsTitle = "影视大全单片购买"; |
| | | } |
| | | String returnUrl = getPaySuccessUrl(id); |
| | | String notifyUrl = Constant.HOST + "/BuWan/alipay/pay"; |
| | | AlipayAppInfo appInfo = getAlipayApp(); |
| | | String form = AlipayH5PayUtil.createOrderForm(appInfo, orderNo, money, goodsTitle, returnUrl, notifyUrl); |
| | | return form; |
| | | } catch (AlipayApiException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public static String getPaySuccessUrl(String id) { |
| | | return "http://vip.ysdq.yeshitv.com/pay_success.html?id=" + id; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 微信下单 |
| | | * |
| | | * @param ip |
| | | * @param orderNo |
| | | * @param money |
| | | * @param title |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static String createWXOrder(String id, String ip, String orderNo, BigDecimal money, String title) throws Exception { |
| | | WXPlaceOrderParams params = new WXPlaceOrderParams(); |
| | | params.setIp(ip); |
| | | params.setOrderNo(orderNo); |
| | | params.setNotifyUrl(Constant.HOST + "/BuWan/wx/pay/vip"); |
| | | params.setFee(money); |
| | | params.setBody(title); |
| | | params.setApp(getWXAPP()); |
| | | String returnUrl = "http://vip.ysdq.yeshitv.com/pay_finish.html?id=" + id; |
| | | String payUrl = WXPayV3Util.createH5Order(params, returnUrl); |
| | | return payUrl; |
| | | } |
| | | |
| | | |
| | | } |