d
This commit is contained in:
@@ -346,8 +346,13 @@ public class PayActivity extends BaseActivity<ActivityPayBinding> {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
notifyUrl = ApiConfig.CALLBACK_PAYMENT_PAY;
|
notifyUrl = ApiConfig.CALLBACK_PAYMENT_PAY;
|
||||||
tradeNo = billNumber+"|"+cart_id;
|
tradeNo = order_number+"|"+cart_id;
|
||||||
|
// tradeNo = cart_id;
|
||||||
//String number = mDataBinding.number.getText().toString();
|
//String number = mDataBinding.number.getText().toString();
|
||||||
|
Log.e("支付宝cart_id值==",cart_id);
|
||||||
|
Log.e("支付宝notifyUrl值==",notifyUrl);
|
||||||
|
Log.e("支付宝tradeNo值==",tradeNo);
|
||||||
|
Log.e("支付宝payment_amount值==",payment_amount);
|
||||||
aliPayManager.startPay("", "", tradeNo, payment_amount, notifyUrl);
|
aliPayManager.startPay("", "", tradeNo, payment_amount, notifyUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,22 +141,60 @@ public class AliPayManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public void startPay(String subject, String body, String tradeNo, String totalAmount, String notifyUrl) {
|
public void startPay(String subject, String body, String tradeNo, String totalAmount, String notifyUrl) {
|
||||||
|
// if (TextUtils.isEmpty(APPID) || (TextUtils.isEmpty(RSA2_PRIVATE) && TextUtils.isEmpty(RSA_PRIVATE))) {
|
||||||
|
// new AlertDialog.Builder(context).setTitle("警告").setMessage("需要配置APPID | RSA_PRIVATE")
|
||||||
|
// .setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||||
|
// public void onClick(DialogInterface dialoginterface, int i) {
|
||||||
|
// context.finish();
|
||||||
|
// }
|
||||||
|
// }).show();
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 这里只是为了方便直接向商户展示支付宝的整个支付流程;所以Demo中加签过程直接放在客户端完成;
|
||||||
|
// * 真实App里,privateKey等数据严禁放在客户端,加签过程务必要放在服务端完成;
|
||||||
|
// * 防止商户私密数据泄露,造成不必要的资金损失,及面临各种安全风险;
|
||||||
|
// *
|
||||||
|
// * orderInfo的获取必须来自服务端;
|
||||||
|
// */
|
||||||
|
// boolean rsa2 = (RSA2_PRIVATE.length() > 0);
|
||||||
|
// Map<String, String> params = OrderInfoUtil2_0.buildOrderParamMap(APPID, subject, body, tradeNo, totalAmount, notifyUrl, rsa2);
|
||||||
|
// String orderParam = OrderInfoUtil2_0.buildOrderParam(params);
|
||||||
|
//
|
||||||
|
// String privateKey = rsa2 ? RSA2_PRIVATE : RSA_PRIVATE;
|
||||||
|
// String sign = OrderInfoUtil2_0.getSign(params, privateKey, rsa2);
|
||||||
|
// final String orderInfo = orderParam + "&" + sign;
|
||||||
|
//
|
||||||
|
// Runnable payRunnable = new Runnable() {
|
||||||
|
// @Override
|
||||||
|
// public void run() {
|
||||||
|
// PayTask alipay = new PayTask(context);
|
||||||
|
// Map<String, String> result = alipay.payV2(orderInfo, true);
|
||||||
|
// Log.i("msp", result.toString());
|
||||||
|
//
|
||||||
|
// Message msg = new Message();
|
||||||
|
// msg.what = SDK_PAY_FLAG;
|
||||||
|
// msg.obj = result;
|
||||||
|
// mHandler.sendMessage(msg);
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// Thread payThread = new Thread(payRunnable);
|
||||||
|
// payThread.start();
|
||||||
|
|
||||||
|
|
||||||
if (TextUtils.isEmpty(APPID) || (TextUtils.isEmpty(RSA2_PRIVATE) && TextUtils.isEmpty(RSA_PRIVATE))) {
|
if (TextUtils.isEmpty(APPID) || (TextUtils.isEmpty(RSA2_PRIVATE) && TextUtils.isEmpty(RSA_PRIVATE))) {
|
||||||
new AlertDialog.Builder(context).setTitle("警告").setMessage("需要配置APPID | RSA_PRIVATE")
|
// showAlert(this, getString(R.string.error_missing_appid_rsa_private));
|
||||||
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialoginterface, int i) {
|
|
||||||
context.finish();
|
|
||||||
}
|
|
||||||
}).show();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* 这里只是为了方便直接向商户展示支付宝的整个支付流程;所以Demo中加签过程直接放在客户端完成;
|
* 这里只是为了方便直接向商户展示支付宝的整个支付流程;所以Demo中加签过程直接放在客户端完成;
|
||||||
* 真实App里,privateKey等数据严禁放在客户端,加签过程务必要放在服务端完成;
|
* 真实App里,privateKey等数据严禁放在客户端,加签过程务必要放在服务端完成;
|
||||||
* 防止商户私密数据泄露,造成不必要的资金损失,及面临各种安全风险;
|
* 防止商户私密数据泄露,造成不必要的资金损失,及面临各种安全风险;
|
||||||
*
|
*
|
||||||
* orderInfo的获取必须来自服务端;
|
* orderInfo 的获取必须来自服务端;
|
||||||
*/
|
*/
|
||||||
boolean rsa2 = (RSA2_PRIVATE.length() > 0);
|
boolean rsa2 = (RSA2_PRIVATE.length() > 0);
|
||||||
Map<String, String> params = OrderInfoUtil2_0.buildOrderParamMap(APPID, subject, body, tradeNo, totalAmount, notifyUrl, rsa2);
|
Map<String, String> params = OrderInfoUtil2_0.buildOrderParamMap(APPID, subject, body, tradeNo, totalAmount, notifyUrl, rsa2);
|
||||||
@@ -166,7 +204,8 @@ public class AliPayManager {
|
|||||||
String sign = OrderInfoUtil2_0.getSign(params, privateKey, rsa2);
|
String sign = OrderInfoUtil2_0.getSign(params, privateKey, rsa2);
|
||||||
final String orderInfo = orderParam + "&" + sign;
|
final String orderInfo = orderParam + "&" + sign;
|
||||||
|
|
||||||
Runnable payRunnable = new Runnable() {
|
final Runnable payRunnable = new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PayTask alipay = new PayTask(context);
|
PayTask alipay = new PayTask(context);
|
||||||
@@ -180,6 +219,7 @@ public class AliPayManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 必须异步调用
|
||||||
Thread payThread = new Thread(payRunnable);
|
Thread payThread = new Thread(payRunnable);
|
||||||
payThread.start();
|
payThread.start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,21 +23,31 @@ public class OrderInfoUtil2_0 {
|
|||||||
Map<String, String> keyValues = new HashMap<String, String>();
|
Map<String, String> keyValues = new HashMap<String, String>();
|
||||||
|
|
||||||
keyValues.put("app_id", app_id);
|
keyValues.put("app_id", app_id);
|
||||||
|
keyValues.put("biz_content", "{\"timeout_express\":\"30m\",\"product_code\":\"QUICK_MSECURITY_PAY\",\"total_amount\":\"" + totalAmount + "\",\"subject\":\"1\",\"body\":\"我是测试数据\",\"out_trade_no\":\"" + tradeNo + "\"}");
|
||||||
keyValues.put("biz_content", "{\"timeout_express\":\"30m\",\"product_code\":\"QUICK_MSECURITY_PAY\",\"total_amount\":\"" + totalAmount + "\",\"subject\":\"" + subject + "\",\"body\":\"" + body + "\",\"out_trade_no\":\"" + tradeNo + "\"}");
|
// keyValues.put("biz_content", "{\"timeout_express\":\"30m\",\"product_code\":\"QUICK_MSECURITY_PAY\",\"total_amount\":\"0.01\",\"subject\":\"1\",\"body\":\"我是测试数据\",\"out_trade_no\":\"" + getOutTradeNo() + "\"}");
|
||||||
|
|
||||||
keyValues.put("charset", "utf-8");
|
keyValues.put("charset", "utf-8");
|
||||||
|
|
||||||
keyValues.put("method", "alipay.trade.app.pay");
|
keyValues.put("method", "alipay.trade.app.pay");
|
||||||
|
|
||||||
keyValues.put("sign_type", rsa2 ? "RSA2" : "RSA");
|
keyValues.put("sign_type", rsa2 ? "RSA2" : "RSA");
|
||||||
|
|
||||||
keyValues.put("timestamp", getCurFormatTime());
|
keyValues.put("timestamp", getCurFormatTime());
|
||||||
|
|
||||||
keyValues.put("notify_url", notifyurl);
|
keyValues.put("notify_url", notifyurl);
|
||||||
|
|
||||||
keyValues.put("version", "1.0");
|
keyValues.put("version", "1.0");
|
||||||
|
|
||||||
|
//+++++++++++++++++++++
|
||||||
|
|
||||||
|
// keyValues.put("app_id", app_id);
|
||||||
|
//
|
||||||
|
// keyValues.put("biz_content", "{\"timeout_express\":\"30m\",\"product_code\":\"QUICK_MSECURITY_PAY\",\"total_amount\":\"0.01\",\"subject\":\"1\",\"body\":\"我是测试数据\",\"out_trade_no\":\"" + getOutTradeNo() + "\"}");
|
||||||
|
//
|
||||||
|
// keyValues.put("charset", "utf-8");
|
||||||
|
//
|
||||||
|
// keyValues.put("method", "alipay.trade.app.pay");
|
||||||
|
//
|
||||||
|
// keyValues.put("sign_type", rsa2 ? "RSA2" : "RSA");
|
||||||
|
//
|
||||||
|
// keyValues.put("timestamp", getCurFormatTime());
|
||||||
|
//
|
||||||
|
// keyValues.put("version", "1.0");
|
||||||
|
|
||||||
return keyValues;
|
return keyValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +74,20 @@ public class OrderInfoUtil2_0 {
|
|||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 要求外部订单号必须唯一。
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static String getOutTradeNo() {
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("MMddHHmmss", Locale.getDefault());
|
||||||
|
Date date = new Date();
|
||||||
|
String key = format.format(date);
|
||||||
|
|
||||||
|
Random r = new Random();
|
||||||
|
key = key + r.nextInt();
|
||||||
|
key = key.substring(0, 15);
|
||||||
|
return key;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 拼接键值对
|
* 拼接键值对
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -6,6 +6,42 @@ import java.security.spec.PKCS8EncodedKeySpec;
|
|||||||
|
|
||||||
public class SignUtils {
|
public class SignUtils {
|
||||||
|
|
||||||
|
// private static final String ALGORITHM = "RSA";
|
||||||
|
//
|
||||||
|
// private static final String SIGN_ALGORITHMS = "SHA1WithRSA";
|
||||||
|
//
|
||||||
|
// private static final String SIGN_SHA256RSA_ALGORITHMS = "SHA256WithRSA";
|
||||||
|
//
|
||||||
|
// private static final String DEFAULT_CHARSET = "UTF-8";
|
||||||
|
//
|
||||||
|
// private static String getAlgorithms(boolean rsa2) {
|
||||||
|
// return rsa2 ? SIGN_SHA256RSA_ALGORITHMS : SIGN_ALGORITHMS;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public static String sign(String content, String privateKey, boolean rsa2) {
|
||||||
|
// try {
|
||||||
|
// PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(
|
||||||
|
// Base64.decode(privateKey));
|
||||||
|
// KeyFactory keyFactory = KeyFactory.getInstance(ALGORITHM, "BC");
|
||||||
|
// PrivateKey priKey = keyFactory.generatePrivate(priPKCS8);
|
||||||
|
//
|
||||||
|
// java.security.Signature signature = java.security.Signature
|
||||||
|
// .getInstance(getAlgorithms(rsa2));
|
||||||
|
//
|
||||||
|
// signature.initSign(priKey);
|
||||||
|
// signature.update(content.getBytes(DEFAULT_CHARSET));
|
||||||
|
//
|
||||||
|
// byte[] signed = signature.sign();
|
||||||
|
//
|
||||||
|
// return Base64.encode(signed);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
private static final String ALGORITHM = "RSA";
|
private static final String ALGORITHM = "RSA";
|
||||||
|
|
||||||
private static final String SIGN_ALGORITHMS = "SHA1WithRSA";
|
private static final String SIGN_ALGORITHMS = "SHA1WithRSA";
|
||||||
@@ -17,13 +53,13 @@ public class SignUtils {
|
|||||||
private static String getAlgorithms(boolean rsa2) {
|
private static String getAlgorithms(boolean rsa2) {
|
||||||
return rsa2 ? SIGN_SHA256RSA_ALGORITHMS : SIGN_ALGORITHMS;
|
return rsa2 ? SIGN_SHA256RSA_ALGORITHMS : SIGN_ALGORITHMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String sign(String content, String privateKey, boolean rsa2) {
|
public static String sign(String content, String privateKey, boolean rsa2) {
|
||||||
try {
|
try {
|
||||||
PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(
|
PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(
|
||||||
Base64.decode(privateKey));
|
Base64.decode(privateKey));
|
||||||
KeyFactory keyFactory = KeyFactory.getInstance(ALGORITHM, "BC");
|
KeyFactory keyf = KeyFactory.getInstance(ALGORITHM);
|
||||||
PrivateKey priKey = keyFactory.generatePrivate(priPKCS8);
|
PrivateKey priKey = keyf.generatePrivate(priPKCS8);
|
||||||
|
|
||||||
java.security.Signature signature = java.security.Signature
|
java.security.Signature signature = java.security.Signature
|
||||||
.getInstance(getAlgorithms(rsa2));
|
.getInstance(getAlgorithms(rsa2));
|
||||||
|
|||||||
Reference in New Issue
Block a user