From a489a6d00d713a3585e557db3a6f765abdf48708 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Mon, 5 Dec 2022 14:18:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4AliPay=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yunbao/common/Constants.java | 3 +- .../com/yunbao/common/pay/PayPresenter.java | 22 +- .../yunbao/common/pay/ali/AliPayBuilder.java | 411 +++++++++--------- 3 files changed, 219 insertions(+), 217 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/Constants.java b/common/src/main/java/com/yunbao/common/Constants.java index 19eba69b3..d6ac40f00 100644 --- a/common/src/main/java/com/yunbao/common/Constants.java +++ b/common/src/main/java/com/yunbao/common/Constants.java @@ -76,7 +76,7 @@ public class Constants { public static final String PAY_BUY_COIN_ALI = "Charge.getAliOrder"; public static final String PAY_BUY_COIN_WX = "Charge.getWxOrder"; - public static final String PACKAGE_NAME_ALI = "com.eg.android.AlipayGphone";//支付宝的包名 +// public static final String PACKAGE_NAME_ALI = "com.eg.android.AlipayGphone";//支付宝的包名 public static final String PACKAGE_NAME_WX = "com.tencent.mm";//微信的包名 public static final String PACKAGE_NAME_QQ = "com.tencent.mobileqq";//QQ的包名 public static final String LAT = "lat"; @@ -289,5 +289,6 @@ public class Constants { public static String isSetRemarkText = "";//修改的备注信息 public static boolean isShowLiveDialog = false;//是否在直播间打开单聊 public static int firstInto = 0;// + public static long runTime = System.currentTimeMillis(); } diff --git a/common/src/main/java/com/yunbao/common/pay/PayPresenter.java b/common/src/main/java/com/yunbao/common/pay/PayPresenter.java index caf5c90c8..cef5e3b2c 100644 --- a/common/src/main/java/com/yunbao/common/pay/PayPresenter.java +++ b/common/src/main/java/com/yunbao/common/pay/PayPresenter.java @@ -295,21 +295,21 @@ public class PayPresenter { if (mActivity == null || TextUtils.isEmpty(mServiceNameAli)|| TextUtils.isEmpty(mAliCallbackUrl)) { return; } - if (!CommonAppConfig.isAppExist(Constants.PACKAGE_NAME_ALI)) { - ToastUtil.show(R.string.coin_ali_not_install); - return; - } +// if (!CommonAppConfig.isAppExist(Constants.PACKAGE_NAME_ALI)) { +// ToastUtil.show(R.string.coin_ali_not_install); +// return; +// } if (TextUtils.isEmpty(mAliPartner) || TextUtils.isEmpty(mAliSellerId) || TextUtils.isEmpty(mAliPrivateKey)) { ToastUtil.show(Constants.PAY_ALI_NOT_ENABLE); return; } - AliPayBuilder builder = new AliPayBuilder(mActivity, mAliPartner, mAliSellerId, mAliPrivateKey); - builder.setMoney(money); - builder.setGoodsName(goodsName); - builder.setCallbackUrl(mAliCallbackUrl); - builder.setOrderParams(StringUtil.contact(mServiceNameAli, orderParams)); - builder.setPayCallback(mPayCallback); - builder.pay(); +// AliPayBuilder builder = new AliPayBuilder(mActivity, mAliPartner, mAliSellerId, mAliPrivateKey); +// builder.setMoney(money); +// builder.setGoodsName(goodsName); +// builder.setCallbackUrl(mAliCallbackUrl); +// builder.setOrderParams(StringUtil.contact(mServiceNameAli, orderParams)); +// builder.setPayCallback(mPayCallback); +// builder.pay(); } diff --git a/common/src/main/java/com/yunbao/common/pay/ali/AliPayBuilder.java b/common/src/main/java/com/yunbao/common/pay/ali/AliPayBuilder.java index a2fa25e89..83dc7b994 100644 --- a/common/src/main/java/com/yunbao/common/pay/ali/AliPayBuilder.java +++ b/common/src/main/java/com/yunbao/common/pay/ali/AliPayBuilder.java @@ -22,213 +22,214 @@ import java.util.Map; /** * Created by cxf on 2017/9/21. + * 禁用支付宝 */ - +@Deprecated public class AliPayBuilder { - - private Activity mActivity; - private String mPartner;// 商户ID - private String mSellerId; // 商户收款账号 - private String mPrivateKey; // 商户私钥,pkcs8格式 - private String mPayInfo;//支付宝订单信息 包括 商品信息,订单签名,签名类型 - private String mGoodsName;//商品名称 - private String mMoney;//要支付的金额 - private String mOrderParams;//订单获取订单需要的参数 - private String mCallbackUrl;//支付宝充值回调地址 - private PayHandler mPayHandler; - - public AliPayBuilder(Activity activity, String partner, String sellerId, String privateKey) { - mActivity = new WeakReference<>(activity).get(); - mPartner = partner; - mSellerId = sellerId; - mPrivateKey = privateKey; - } - - public AliPayBuilder setMoney(String money) { - mMoney = money; - return this; - } - - public AliPayBuilder setGoodsName(String goodsName) { - mGoodsName = goodsName; - return this; - } - - public AliPayBuilder setOrderParams(String orderParams) { - mOrderParams = orderParams; - return this; - } - - - public AliPayBuilder setPayCallback(PayCallback callback) { - mPayHandler = new PayHandler(callback); - return this; - } - - public void setCallbackUrl(String callbackUrl) { - mCallbackUrl = callbackUrl; - } - - /** - * 从服务器端获取订单号,即下单 - */ - public void pay() { - if (TextUtils.isEmpty(mOrderParams) || TextUtils.isEmpty(mMoney) || TextUtils.isEmpty(mGoodsName)|| TextUtils.isEmpty(mCallbackUrl)) { - return; - } - CommonHttpUtil.getAliOrder(mOrderParams, new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0 && info.length > 0) { - JSONObject obj = JSON.parseObject(info[0]); - String orderInfo = createAliOrder(obj.getString("orderid"));//商品信息 - String sign = getOrderSign(orderInfo);//订单签名 - if (TextUtils.isEmpty(sign)) { - ToastUtil.show("商户私钥错误,订单签名失败"); - return; - } - sign = urlEncode(sign); - String signType = "sign_type=\"RSA\"";//签名类型 - mPayInfo = orderInfo + "&sign=\"" + sign + "\"&" + signType; - L.e("支付宝订单信息----->" + mPayInfo); - invokeAliPay(); - } - } - - @Override - public boolean showLoadingDialog() { - return true; - } - - @Override - public Dialog createLoadingDialog() { - return DialogUitl.loadingDialog(mActivity); - } - - - }); - } - - /** - * 根据订单号和商品信息生成支付宝格式的订单信息 - * - * @param orderId 服务器返回的订单号 - * @return - */ - private String createAliOrder(String orderId) { - // 合作者身份ID - String orderInfo = "partner=" + "\"" + mPartner + "\""; - - // 卖家支付宝账号 - orderInfo += "&seller_id=" + "\"" + mSellerId + "\""; - - // 商户网站唯一订单号 - orderInfo += "&out_trade_no=" + "\"" + orderId + "\""; - - // 商品名称 - orderInfo += "&subject=" + "\"" + mGoodsName + "\""; - - // 商品详情 - orderInfo += "&body=" + "\"" + mGoodsName + "\""; - - // 商品金额 - orderInfo += "&total_fee=" + "\"" + mMoney + "\""; - - // 服务器异步通知页面路径 //服务器异步通知页面路径 参数 notify_url,如果商户没设定,则不会进行该操作 - orderInfo += "¬ify_url=" + "\"" + mCallbackUrl + "\""; - - // 接口名称, 固定值 - orderInfo += "&service=\"mobile.securitypay.pay\""; - - // 支付类型, 固定值 - orderInfo += "&payment_type=\"1\""; - - // 参数编码, 固定值 - orderInfo += "&_input_charset=\"utf-8\""; - - // 设置未付款交易的超时时间 - // 默认30分钟,一旦超时,该笔交易就会自动被关闭。 - // 取值范围:1m〜15d。 - // m-分钟,h-小时,d-天,1c-当天(无论交易何时创建,都在0点关闭)。 - // 该参数数值不接受小数点,如1.5h,可转换为90m。 - orderInfo += "&it_b_pay=\"30m\""; - - // 支付宝处理完请求后,当前页面跳转到商户指定页面的路径,可空 - orderInfo += "&return_url=\"m.alipay.com\""; - - // 调用银行卡支付,需配置此参数,参与签名, 固定值 - // orderInfo += "&paymethod=\"expressGateway\""; - - return orderInfo; - } - - /** - * 根据订单信息生成订单的签名 - * - * @param orderInfo 订单信息 - * @return - */ - private String getOrderSign(String orderInfo) { - return SignUtils.sign(orderInfo, mPrivateKey); - } - - /** - * 对订单签名进行urlencode转码 - * - * @param sign 签名 - * @return - */ - private String urlEncode(String sign) { - try { - sign = URLEncoder.encode(sign, "UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - return sign; - } - - /** - * 调用支付宝sdk - */ - private void invokeAliPay() { -// new Thread(new Runnable() { +// +// private Activity mActivity; +// private String mPartner;// 商户ID +// private String mSellerId; // 商户收款账号 +// private String mPrivateKey; // 商户私钥,pkcs8格式 +// private String mPayInfo;//支付宝订单信息 包括 商品信息,订单签名,签名类型 +// private String mGoodsName;//商品名称 +// private String mMoney;//要支付的金额 +// private String mOrderParams;//订单获取订单需要的参数 +// private String mCallbackUrl;//支付宝充值回调地址 +// private PayHandler mPayHandler; +// +// public AliPayBuilder(Activity activity, String partner, String sellerId, String privateKey) { +// mActivity = new WeakReference<>(activity).get(); +// mPartner = partner; +// mSellerId = sellerId; +// mPrivateKey = privateKey; +// } +// +// public AliPayBuilder setMoney(String money) { +// mMoney = money; +// return this; +// } +// +// public AliPayBuilder setGoodsName(String goodsName) { +// mGoodsName = goodsName; +// return this; +// } +// +// public AliPayBuilder setOrderParams(String orderParams) { +// mOrderParams = orderParams; +// return this; +// } +// +// +// public AliPayBuilder setPayCallback(PayCallback callback) { +// mPayHandler = new PayHandler(callback); +// return this; +// } +// +// public void setCallbackUrl(String callbackUrl) { +// mCallbackUrl = callbackUrl; +// } +// +// /** +// * 从服务器端获取订单号,即下单 +// */ +// public void pay() { +// if (TextUtils.isEmpty(mOrderParams) || TextUtils.isEmpty(mMoney) || TextUtils.isEmpty(mGoodsName)|| TextUtils.isEmpty(mCallbackUrl)) { +// return; +// } +// CommonHttpUtil.getAliOrder(mOrderParams, new HttpCallback() { // @Override -// public void run() { -//// PayTask alipay = new PayTask(mActivity); -// //执行支付,这是一个耗时操作,最后返回支付的结果,用handler发送到主线程 -//// Map result = alipay.payV2(mPayInfo, true); -//// L.e("支付宝返回结果----->" + result); -//// if (mPayHandler != null) { -//// Message msg = Message.obtain(); -//// msg.obj = result; -//// mPayHandler.sendMessage(msg); -//// } -//// } -// }).start(); - } - - - private static class PayHandler extends Handler { - - private PayCallback mPayCallback; - - public PayHandler(PayCallback payCallback) { - mPayCallback = new WeakReference<>(payCallback).get(); - } - - @Override - public void handleMessage(Message msg) { - if (mPayCallback != null) { - @SuppressWarnings("unchecked") - Map result = (Map) msg.obj; - if ("9000".equals(result.get("resultStatus"))) { - mPayCallback.onSuccess(); - } else { - mPayCallback.onFailed(); - } - } - mPayCallback = null; - } - } +// public void onSuccess(int code, String msg, String[] info) { +// if (code == 0 && info.length > 0) { +// JSONObject obj = JSON.parseObject(info[0]); +// String orderInfo = createAliOrder(obj.getString("orderid"));//商品信息 +// String sign = getOrderSign(orderInfo);//订单签名 +// if (TextUtils.isEmpty(sign)) { +// ToastUtil.show("商户私钥错误,订单签名失败"); +// return; +// } +// sign = urlEncode(sign); +// String signType = "sign_type=\"RSA\"";//签名类型 +// mPayInfo = orderInfo + "&sign=\"" + sign + "\"&" + signType; +// L.e("支付宝订单信息----->" + mPayInfo); +// invokeAliPay(); +// } +// } +// +// @Override +// public boolean showLoadingDialog() { +// return true; +// } +// +// @Override +// public Dialog createLoadingDialog() { +// return DialogUitl.loadingDialog(mActivity); +// } +// +// +// }); +// } +// +// /** +// * 根据订单号和商品信息生成支付宝格式的订单信息 +// * +// * @param orderId 服务器返回的订单号 +// * @return +// */ +// private String createAliOrder(String orderId) { +// // 合作者身份ID +// String orderInfo = "partner=" + "\"" + mPartner + "\""; +// +// // 卖家支付宝账号 +// orderInfo += "&seller_id=" + "\"" + mSellerId + "\""; +// +// // 商户网站唯一订单号 +// orderInfo += "&out_trade_no=" + "\"" + orderId + "\""; +// +// // 商品名称 +// orderInfo += "&subject=" + "\"" + mGoodsName + "\""; +// +// // 商品详情 +// orderInfo += "&body=" + "\"" + mGoodsName + "\""; +// +// // 商品金额 +// orderInfo += "&total_fee=" + "\"" + mMoney + "\""; +// +// // 服务器异步通知页面路径 //服务器异步通知页面路径 参数 notify_url,如果商户没设定,则不会进行该操作 +// orderInfo += "¬ify_url=" + "\"" + mCallbackUrl + "\""; +// +// // 接口名称, 固定值 +// orderInfo += "&service=\"mobile.securitypay.pay\""; +// +// // 支付类型, 固定值 +// orderInfo += "&payment_type=\"1\""; +// +// // 参数编码, 固定值 +// orderInfo += "&_input_charset=\"utf-8\""; +// +// // 设置未付款交易的超时时间 +// // 默认30分钟,一旦超时,该笔交易就会自动被关闭。 +// // 取值范围:1m〜15d。 +// // m-分钟,h-小时,d-天,1c-当天(无论交易何时创建,都在0点关闭)。 +// // 该参数数值不接受小数点,如1.5h,可转换为90m。 +// orderInfo += "&it_b_pay=\"30m\""; +// +// // 支付宝处理完请求后,当前页面跳转到商户指定页面的路径,可空 +// orderInfo += "&return_url=\"m.alipay.com\""; +// +// // 调用银行卡支付,需配置此参数,参与签名, 固定值 +// // orderInfo += "&paymethod=\"expressGateway\""; +// +// return orderInfo; +// } +// +// /** +// * 根据订单信息生成订单的签名 +// * +// * @param orderInfo 订单信息 +// * @return +// */ +// private String getOrderSign(String orderInfo) { +// return SignUtils.sign(orderInfo, mPrivateKey); +// } +// +// /** +// * 对订单签名进行urlencode转码 +// * +// * @param sign 签名 +// * @return +// */ +// private String urlEncode(String sign) { +// try { +// sign = URLEncoder.encode(sign, "UTF-8"); +// } catch (UnsupportedEncodingException e) { +// e.printStackTrace(); +// } +// return sign; +// } +// +// /** +// * 调用支付宝sdk +// */ +// private void invokeAliPay() { +//// new Thread(new Runnable() { +//// @Override +//// public void run() { +////// PayTask alipay = new PayTask(mActivity); +//// //执行支付,这是一个耗时操作,最后返回支付的结果,用handler发送到主线程 +////// Map result = alipay.payV2(mPayInfo, true); +////// L.e("支付宝返回结果----->" + result); +////// if (mPayHandler != null) { +////// Message msg = Message.obtain(); +////// msg.obj = result; +////// mPayHandler.sendMessage(msg); +////// } +////// } +//// }).start(); +// } +// +// +// private static class PayHandler extends Handler { +// +// private PayCallback mPayCallback; +// +// public PayHandler(PayCallback payCallback) { +// mPayCallback = new WeakReference<>(payCallback).get(); +// } +// +// @Override +// public void handleMessage(Message msg) { +// if (mPayCallback != null) { +// @SuppressWarnings("unchecked") +// Map result = (Map) msg.obj; +// if ("9000".equals(result.get("resultStatus"))) { +// mPayCallback.onSuccess(); +// } else { +// mPayCallback.onFailed(); +// } +// } +// mPayCallback = null; +// } +// } }