Commit 1b5fd834 authored by mengcuiguang2's avatar mengcuiguang2

delete alipay

parent 2c6730bc
/build
mapping.txt
seeds.txt
unused.txt
priguardMapping.txt
plugins {
id 'com.android.library'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
// implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
implementation fileTree(dir: 'libs', include: ['*.jar'])
api 'com.alipay.sdk:alipaysdk-android:+@aar'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
compileOnly project(":rxpay")
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jobo.alipay">
</manifest>
\ No newline at end of file
/*
******************************* Copyright (c)*********************************\
**
** (c) Copyright 2017, King, china
** All Rights Reserved
**
** By(King)
**
**------------------------------------------------------------------------------
*/
package com.jobo.alipay;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import com.alipay.sdk.app.PayTask;
import com.jobo.rxpay.base.IPayStrategy;
import com.jobo.rxpay.callback.IPayCallback;
import java.util.Map;
/**
* @Desc:
* @author: admin wsj
* @Date: 2021/12/28 2:34 下午
* @see <a href="https://docs.open.alipay.com/204/">Des</a>
*/
public class AliPay implements IPayStrategy<AlipayInfoImpl> {
private static final int SDK_PAY_FLAG = 6406;
private Activity mActivity;
private AlipayInfoImpl alipayInfoImpli;
private static IPayCallback sPayCallback;
@Override
public void pay(Activity activity, AlipayInfoImpl payInfo, IPayCallback payCallback) {
this.mActivity = activity;
this.alipayInfoImpli = payInfo;
sPayCallback = payCallback;
Runnable payRunnable = new Runnable() {
@Override
public void run() {
// 构造PayTask 对象
PayTask alipay = new PayTask(mActivity);
// 调用支付接口,获取支付结果
Map<String,String> result = alipay.payV2(alipayInfoImpli.getOrderInfo(),true);
Message msg = new Message();
msg.what = SDK_PAY_FLAG;
msg.obj = result;
mHandler.sendMessage(msg);
}
};
// 必须异步调用
Thread payThread = new Thread(payRunnable);
payThread.start();
}
@SuppressLint("HandlerLeak")
private static Handler mHandler = new Handler() {
@SuppressWarnings("unused")
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case SDK_PAY_FLAG: {
AliPayResult payResult = new AliPayResult((Map<String, String>) msg.obj);
/**
* 同步返回的结果必须放置到服务端进行验证(验证的规则请看https://doc.open.alipay.com/doc2/
* detail.htm?spm=0.0.0.0.xdvAU6&treeId=59&articleId=103665&
* docType=1) 建议商户依赖异步通知
*/
String resultInfo = payResult.getResult();// 同步返回需要验证的信息
String resultStatus = payResult.getResultStatus();
// 判断resultStatus 为“9000”则代表支付成功,具体状态码代表含义可参考接口文档:
//https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.IXE2Zj&treeId=59&articleId=103671&docType=1
if (TextUtils.equals(resultStatus, ResultCode.CODE_SUCCESS)) {
if (sPayCallback != null) {
sPayCallback.success();
}
} else if(TextUtils.equals(resultStatus, ResultCode.CODE_CANCEL)){
if(sPayCallback != null){
sPayCallback.cancel();
}
} else {
// 其他值就可以判断为支付失败,包括用户主动取消支付,或者系统返回的错误
if (sPayCallback != null) {
sPayCallback.failed(ResultCode.getIntCodeByString(resultStatus), ResultCode.getTextByCode(resultStatus));
}
}
break;
}
default:
break;
}
}
};
}
package com.jobo.alipay; import android.text.TextUtils; import java.util.Map; /** * @Desc: 支付宝支付结果 * @author: admin wsj * @Date: 2021/12/28 2:33 下午 */public class AliPayResult { private String resultStatus; private String result; private String memo; public AliPayResult(Map<String, String> rawResult) { if (rawResult == null) { return; } for (String key : rawResult.keySet()) { if (TextUtils.equals(key, "resultStatus")) { resultStatus = rawResult.get(key); } else if (TextUtils.equals(key, "result")) { result = rawResult.get(key); } else if (TextUtils.equals(key, "memo")) { memo = rawResult.get(key); } } } @Override public String toString() { return "resultStatus={" + resultStatus + "};memo={" + memo + "};result={" + result + "}"; } /** * @return the resultStatus */ public String getResultStatus() { return resultStatus; } /** * @return the memo */ public String getMemo() { return memo; } /** * @return the result */ public String getResult() { return result; }}
\ No newline at end of file
package com.jobo.alipay;
import com.jobo.rxpay.base.IPayInfo;
/**
* @Desc: 包含支付宝支付类型和支付信息
* @author: admin wsj
* @Date: 2021/12/28 2:33 下午
*/
public class AlipayInfoImpl implements IPayInfo {
private String orderInfo;
public String getOrderInfo() {
return orderInfo;
}
public void setOrderInfo(String orderInfo) {
this.orderInfo = orderInfo;
}
}
package com.jobo.alipay;
import java.util.HashMap;
/**
* @Desc: 支付宝code
* @author: admin wsj
* @Date: 2021/12/28 2:33 下午
*/
public class ResultCode {
private static final HashMap<String, String> sErrorMap = new HashMap<>();
public static final String CODE_SUCCESS = "9000";
public static final String CODE_HANDLING = "8000";
public static final String CODE_FAIL = "4000";
public static final String CODE_REPEAT = "5000";
public static final String CODE_CANCEL = "6001";
public static final String CODE_NETWORK = "6002";
public static final String CODE_UNKNOWN = "6004";
private static final String TEXT_SUCCESS = "订单支付成功";
private static final String TEXT_HANDLING = "正在处理中";
private static final String TEXT_FAIL = "订单支付失败";
private static final String TEXT_REPEAT = "重复请求";
private static final String TEXT_CANCEL = "用户中途取消";
private static final String TEXT_NETWORK = "网络连接出错";
private static final String TEXT_UNKNOWN = "支付结果未知";
private static final String TEXT_ERROR = "未知错误";
static {
sErrorMap.put(CODE_SUCCESS, TEXT_SUCCESS);
sErrorMap.put(CODE_HANDLING, TEXT_HANDLING);
sErrorMap.put(CODE_FAIL, TEXT_FAIL);
sErrorMap.put(CODE_REPEAT, TEXT_REPEAT);
sErrorMap.put(CODE_CANCEL, TEXT_CANCEL);
sErrorMap.put(CODE_NETWORK, TEXT_NETWORK);
sErrorMap.put(CODE_UNKNOWN, TEXT_UNKNOWN);
}
private ResultCode() {
}
public static String getTextByCode(String code) {
String text = sErrorMap.get(code);
if (text == null) {
return TEXT_ERROR;
}
return text;
}
public static int getIntCodeByString(String errorCode) {
return Integer.parseInt(errorCode);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment