├── app
├── .gitignore
├── libs
│ ├── libammsdk.jar
│ ├── volley-6.0.jar
│ └── alipaySdk-20160516.jar
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── layout
│ │ │ │ ├── activity_wxpay_call_back.xml
│ │ │ │ └── activity_main.xml
│ │ │ └── values-w820dp
│ │ │ │ └── dimens.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── syhd
│ │ │ │ └── payandroid
│ │ │ │ ├── net
│ │ │ │ ├── StringCallback.java
│ │ │ │ ├── HttpUtils.java
│ │ │ │ └── HttpLoader.java
│ │ │ │ ├── alipay
│ │ │ │ ├── server
│ │ │ │ │ ├── SignUtils.java
│ │ │ │ │ ├── AlipayServer.java
│ │ │ │ │ └── Base64.java
│ │ │ │ └── client
│ │ │ │ │ ├── AlipayResult.java
│ │ │ │ │ └── Alipay.java
│ │ │ │ ├── wxapi
│ │ │ │ └── WXPayEntryActivity.java
│ │ │ │ ├── weixin
│ │ │ │ └── WXPay.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── syhd
│ │ │ └── payandroid
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── syhd
│ │ └── payandroid
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── README.md
├── .gitattributes
├── gradle.properties
├── .gitignore
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/libs/libammsdk.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanbaokun/AndroidPay/HEAD/app/libs/libammsdk.jar
--------------------------------------------------------------------------------
/app/libs/volley-6.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanbaokun/AndroidPay/HEAD/app/libs/volley-6.0.jar
--------------------------------------------------------------------------------
/app/libs/alipaySdk-20160516.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanbaokun/AndroidPay/HEAD/app/libs/alipaySdk-20160516.jar
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PayAndroid
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanbaokun/AndroidPay/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanbaokun/AndroidPay/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanbaokun/AndroidPay/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanbaokun/AndroidPay/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanbaokun/AndroidPay/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanbaokun/AndroidPay/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/syhd/payandroid/net/StringCallback.java:
--------------------------------------------------------------------------------
1 | package com.syhd.payandroid.net;
2 |
3 |
4 | public abstract class StringCallback {
5 | public abstract void onError(String request);
6 |
7 | public abstract void onResponse(String response);
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_wxpay_call_back.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AndroidPay
2 | 基于微信和支付宝的支付demo,可以直接拷贝代码到项目中使用
3 |
4 | >支付宝可以进行参数测试,
5 | >微信需要自行编写服务器代码获取支付参数(格式代码中已附)
6 | ####微信支付常见的问题
7 | * 1.微信开放平台的包名和签名是否和本地的一致
8 | * 2.服务器能拿到prepare_id,还是返回-1,查看调起支付接口时的签名是否计算正确
9 | * 3.能调起支付,没有返回消息的,请查看自己项目包下是否有(wxapi.WXPayEntryActivity)
10 | * 4.本地调试时一定要使用正式签名文件进行调试,否则是调不起微信支付窗口的
11 | * 5.网络上遇到说微信缓存会影响返回-1的,目前没有遇到过
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/test/java/com/syhd/payandroid/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.syhd.payandroid;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/syhd/payandroid/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.syhd.payandroid;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Develop\Android\AndroidSDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/syhd/payandroid/net/HttpUtils.java:
--------------------------------------------------------------------------------
1 | package com.syhd.payandroid.net;
2 |
3 | import android.content.Context;
4 |
5 | import java.util.Map;
6 |
7 |
8 | /**
9 | * 使用volley6.0进行网络访问
10 | * Created by 韩宝坤 on 2016/1/14.
11 | */
12 | public class HttpUtils {
13 | /**
14 | * post请求
15 | * @param url 地址
16 | * @param map 参数
17 | * @param mStringCallBack 回调
18 | */
19 | public static void httpPost(Context context,String url, Map map, StringCallback mStringCallBack) {
20 | HttpLoader.getInstance(context).postRequest(url, map, mStringCallBack);
21 | }
22 |
23 | public static void httpGet(Context context,String url, StringCallback mStringCallBack){
24 | HttpLoader.getInstance(context).getRequest(url,mStringCallBack);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
18 |
19 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | signingConfigs {
5 | syhdkey {
6 | keyAlias 'shengyaohudong'
7 | keyPassword 'shengyaohudong888'
8 | storeFile file('C:/Develop/sdkKey/syhdkey.jks')
9 | storePassword 'shengyaohudong888'
10 | }
11 | }
12 | compileSdkVersion 23
13 | buildToolsVersion "23.0.3"
14 |
15 | defaultConfig {
16 | applicationId "com.syhd.payandroid"
17 | minSdkVersion 16
18 | targetSdkVersion 23
19 | versionCode 1
20 | versionName "1.0"
21 | }
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 | }
29 |
30 | dependencies {
31 | compile fileTree(include: ['*.jar'], dir: 'libs')
32 | testCompile 'junit:junit:4.12'
33 | compile 'com.android.support:appcompat-v7:23.4.0'
34 | compile files('libs/alipaySdk-20160516.jar')
35 | compile files('libs/libammsdk.jar')
36 | compile files('libs/volley-6.0.jar')
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/syhd/payandroid/alipay/server/SignUtils.java:
--------------------------------------------------------------------------------
1 | package com.syhd.payandroid.alipay.server;
2 |
3 | import java.security.KeyFactory;
4 | import java.security.PrivateKey;
5 | import java.security.spec.PKCS8EncodedKeySpec;
6 |
7 | public class SignUtils {
8 |
9 | private static final String ALGORITHM = "RSA";
10 |
11 | private static final String SIGN_ALGORITHMS = "SHA1WithRSA";
12 |
13 | private static final String DEFAULT_CHARSET = "UTF-8";
14 |
15 | public static String sign(String content, String privateKey) {
16 | try {
17 | PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(
18 | Base64.decode(privateKey));
19 | KeyFactory keyf = KeyFactory.getInstance(ALGORITHM);
20 | PrivateKey priKey = keyf.generatePrivate(priPKCS8);
21 |
22 | java.security.Signature signature = java.security.Signature
23 | .getInstance(SIGN_ALGORITHMS);
24 |
25 | signature.initSign(priKey);
26 | signature.update(content.getBytes(DEFAULT_CHARSET));
27 |
28 | byte[] signed = signature.sign();
29 |
30 | return Base64.encode(signed);
31 | } catch (Exception e) {
32 | e.printStackTrace();
33 | }
34 |
35 | return null;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 |
38 | # Keystore files
39 | *.jks
40 |
41 | # =========================
42 | # Operating System Files
43 | # =========================
44 |
45 | # OSX
46 | # =========================
47 |
48 | .DS_Store
49 | .AppleDouble
50 | .LSOverride
51 |
52 | # Thumbnails
53 | ._*
54 |
55 | # Files that might appear in the root of a volume
56 | .DocumentRevisions-V100
57 | .fseventsd
58 | .Spotlight-V100
59 | .TemporaryItems
60 | .Trashes
61 | .VolumeIcon.icns
62 |
63 | # Directories potentially created on remote AFP share
64 | .AppleDB
65 | .AppleDesktop
66 | Network Trash Folder
67 | Temporary Items
68 | .apdisk
69 |
70 | # Windows
71 | # =========================
72 |
73 | # Windows image file caches
74 | Thumbs.db
75 | ehthumbs.db
76 |
77 | # Folder config file
78 | Desktop.ini
79 |
80 | # Recycle Bin used on file shares
81 | $RECYCLE.BIN/
82 |
83 | # Windows Installer files
84 | *.cab
85 | *.msi
86 | *.msm
87 | *.msp
88 |
89 | # Windows shortcuts
90 | *.lnk
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/syhd/payandroid/wxapi/WXPayEntryActivity.java:
--------------------------------------------------------------------------------
1 | package com.syhd.payandroid.wxapi;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 |
8 | import com.syhd.payandroid.R;
9 | import com.syhd.payandroid.weixin.WXPay;
10 | import com.tencent.mm.sdk.constants.ConstantsAPI;
11 | import com.tencent.mm.sdk.modelbase.BaseReq;
12 | import com.tencent.mm.sdk.modelbase.BaseResp;
13 | import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
14 |
15 | public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_wxpay_call_back);
21 |
22 | if(WXPay.getInstance() != null) {
23 | WXPay.getInstance().getWXApi().handleIntent(getIntent(), this);
24 | } else {
25 | finish();
26 | }
27 | }
28 |
29 | @Override
30 | protected void onNewIntent(Intent intent) {
31 | super.onNewIntent(intent);
32 | setIntent(intent);
33 | if(WXPay.getInstance() != null) {
34 | WXPay.getInstance().getWXApi().handleIntent(intent, this);
35 | }
36 | }
37 |
38 | @Override
39 | public void onReq(BaseReq baseReq) {
40 |
41 | }
42 |
43 | @Override
44 | public void onResp(BaseResp baseResp) {
45 | if(baseResp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
46 | if(WXPay.getInstance() != null) {
47 | if(baseResp.errStr != null) {
48 | Log.e("wxpay", "errstr=" + baseResp.errStr);
49 | }
50 |
51 | WXPay.getInstance().onResp(baseResp.errCode);
52 | finish();
53 | }
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
30 |
31 |
32 |
37 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/syhd/payandroid/alipay/client/AlipayResult.java:
--------------------------------------------------------------------------------
1 | package com.syhd.payandroid.alipay.client;
2 |
3 | import android.text.TextUtils;
4 |
5 | public class AlipayResult {
6 | private String resultStatus;
7 | private String result;
8 | private String memo;
9 |
10 | public AlipayResult(String rawResult) {
11 |
12 | if (TextUtils.isEmpty(rawResult))
13 | return;
14 |
15 | String[] resultParams = rawResult.split(";");
16 | for (String resultParam : resultParams) {
17 | if (resultParam.startsWith("resultStatus")) {
18 | resultStatus = gatValue(resultParam, "resultStatus");
19 | }
20 | if (resultParam.startsWith("result")) {
21 | result = gatValue(resultParam, "result");
22 | }
23 | if (resultParam.startsWith("memo")) {
24 | memo = gatValue(resultParam, "memo");
25 | }
26 | }
27 |
28 | if (TextUtils.isEmpty(resultStatus)) {
29 | return;
30 | }
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return "resultStatus={" + resultStatus + "};memo={" + memo
36 | + "};result={" + result + "}";
37 | }
38 |
39 | private String gatValue(String content, String key) {
40 | String prefix = key + "={";
41 | return content.substring(content.indexOf(prefix) + prefix.length(),
42 | content.lastIndexOf("}"));
43 | }
44 |
45 | /**
46 | * @return the resultStatus
47 | */
48 | public String getResultStatus() {
49 | return resultStatus;
50 | }
51 |
52 | /**
53 | * @return the memo
54 | */
55 | public String getMemo() {
56 | return memo;
57 | }
58 |
59 | /**
60 | * @return the result
61 | */
62 | public String getResult() {
63 | return result;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/syhd/payandroid/alipay/client/Alipay.java:
--------------------------------------------------------------------------------
1 | package com.syhd.payandroid.alipay.client;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.os.Handler;
6 | import android.text.TextUtils;
7 |
8 | import com.alipay.sdk.app.PayTask;
9 |
10 | /**
11 | * 支付宝支付
12 | * Created by tsy on 16/6/1.
13 | */
14 | public class Alipay {
15 | private String mParams;
16 | private PayTask mPayTask;
17 | private AlipayResultCallBack mCallback;
18 |
19 | public static final int ERROR_RESULT = 1; //支付结果解析错误
20 | public static final int ERROR_PAY = 2; //支付失败
21 | public static final int ERROR_NETWORK = 3; //网络连接错误
22 |
23 | public interface AlipayResultCallBack {
24 | void onSuccess(); //支付成功
25 | void onDealing(); //正在处理中 小概率事件 此时以验证服务端异步通知结果为准
26 | void onError(int error_code); //支付失败
27 | void onCancel(); //支付取消
28 | }
29 |
30 | public Alipay(Context context, String params, AlipayResultCallBack callback) {
31 | mParams = params;
32 | mCallback = callback;
33 | mPayTask = new PayTask((Activity) context);
34 | }
35 |
36 | //支付
37 | public void doPay() {
38 | final Handler handler = new Handler();
39 | new Thread(new Runnable() {
40 | @Override
41 | public void run() {
42 | String result = mPayTask.pay(mParams, true);
43 |
44 | final AlipayResult pay_result = new AlipayResult(result);
45 | handler.post(new Runnable() {
46 | @Override
47 | public void run() {
48 | if(mCallback == null) {
49 | return;
50 | }
51 |
52 | if(pay_result == null) {
53 | mCallback.onError(ERROR_RESULT);
54 | return;
55 | }
56 |
57 | String resultStatus = pay_result.getResultStatus();
58 | if(TextUtils.equals(resultStatus, "9000")) { //支付成功
59 | mCallback.onSuccess();
60 | } else if(TextUtils.equals(resultStatus, "8000")) { //支付结果因为支付渠道原因或者系统原因还在等待支付结果确认,最终交易是否成功以服务端异步通知为准(小概率状态)
61 | mCallback.onDealing();
62 | } else if(TextUtils.equals(resultStatus, "6001")) { //支付取消
63 | mCallback.onCancel();
64 | } else if(TextUtils.equals(resultStatus, "6002")) { //网络连接出错
65 | mCallback.onError(ERROR_NETWORK);
66 | } else if(TextUtils.equals(resultStatus, "4000")) { //支付错误
67 | mCallback.onError(ERROR_PAY);
68 | }
69 | }
70 | });
71 | }
72 | }).start();
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/syhd/payandroid/net/HttpLoader.java:
--------------------------------------------------------------------------------
1 | package com.syhd.payandroid.net;
2 |
3 | import android.content.Context;
4 |
5 | import com.android.volley.AuthFailureError;
6 | import com.android.volley.Request.Method;
7 | import com.android.volley.RequestQueue;
8 | import com.android.volley.Response;
9 | import com.android.volley.VolleyError;
10 | import com.android.volley.toolbox.StringRequest;
11 | import com.android.volley.toolbox.Volley;
12 |
13 | import java.util.HashMap;
14 | import java.util.Map;
15 |
16 | /**
17 | * 封装volley的post&get请求
18 | */
19 | public class HttpLoader {
20 |
21 | public HttpLoader(Context context) {
22 | mQueue = Volley.newRequestQueue(context);
23 | }
24 |
25 | private static HttpLoader httpLoader = null;
26 | private RequestQueue mQueue;
27 |
28 | public synchronized static HttpLoader getInstance(Context context) {
29 | if (httpLoader == null) {
30 | httpLoader = new HttpLoader(context);
31 | }
32 | return httpLoader;
33 | }
34 |
35 | /**
36 | * 封装volley的post&get请求
37 | * @param url
38 | * @param map
39 | * @param mStringCallBack
40 | */
41 | public void postRequest(String url, final Map map, final StringCallback mStringCallBack) {
42 | StringRequest stringRequest = new StringRequest(Method.POST, url, new Response.Listener() {
43 | @Override
44 | public void onResponse(String response) {
45 | mStringCallBack.onResponse(response);
46 | }
47 | }, new Response.ErrorListener() {
48 | @Override
49 | public void onErrorResponse(VolleyError error) {
50 | mStringCallBack.onError(error.getMessage());
51 | }
52 | }) {
53 | @Override
54 | protected Map getParams() throws AuthFailureError {
55 | return map;
56 | }
57 | };
58 | mQueue.add(stringRequest);
59 | }
60 |
61 | /**
62 | * 封装volley的post&get请求
63 | * @param url
64 | * @param mStringCallBack
65 | */
66 | public void getRequest(String url, final StringCallback mStringCallBack) {
67 | StringRequest stringRequest = new StringRequest(Method.GET, url, new Response.Listener() {
68 | @Override
69 | public void onResponse(String response) {
70 | mStringCallBack.onResponse(response);
71 | }
72 | }, new Response.ErrorListener() {
73 | @Override
74 | public void onErrorResponse(VolleyError error) {
75 | mStringCallBack.onError(error.getMessage());
76 | }
77 | }) {
78 | @Override
79 | protected Map getParams() throws AuthFailureError {
80 | return new HashMap<>();
81 | }
82 | };
83 | mQueue.add(stringRequest);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/app/src/main/java/com/syhd/payandroid/alipay/server/AlipayServer.java:
--------------------------------------------------------------------------------
1 | package com.syhd.payandroid.alipay.server;
2 |
3 | import java.io.UnsupportedEncodingException;
4 | import java.net.URLEncoder;
5 |
6 | /**
7 | * Created by lenovo on 2016/7/12.
8 | */
9 | public class AlipayServer {
10 | //商户PID 替换自己的商户id
11 | private static final String PARTNER = "";
12 | //商户收款账号 替换自己的收款账号
13 | private static final String SELLER = "";
14 | //商户私钥,pkcs8格式
15 | public static final String RSA_PRIVATE = "";
16 | /**
17 | * 获取订单信息
18 | * @param orderId 订单号
19 | * @param subject 商品名称
20 | * @param body 商品描述
21 | * @param money 金额
22 | * @param notifyUrl 支付回调地址
23 | * @return
24 | */
25 | public static String getPayInfo(String orderId,String subject, String body, String money,String notifyUrl) {
26 | // 订单
27 | String orderInfo = getOrderInfo(orderId,subject,
28 | body, money,notifyUrl);
29 |
30 | return signOrderInfo(orderInfo);
31 | }
32 |
33 | private static String signOrderInfo(String orderInfo) {
34 |
35 | // 对订单做RSA 签名
36 | String sign = sign(orderInfo);
37 |
38 | try {
39 | // 仅需对sign 做URL编码
40 | sign = URLEncoder.encode(sign, "UTF-8");
41 |
42 | } catch (UnsupportedEncodingException e) {
43 | e.printStackTrace();
44 | }
45 |
46 | // 完整的符合支付宝参数规范的订单信息
47 | String payInfo = orderInfo + "&sign=\"" + sign + "\"&" + getSignType();
48 |
49 | return payInfo;
50 | }
51 |
52 | /**
53 | * create the order info. 创建订单信息
54 | */
55 | private static String getOrderInfo(String orderId, String subject, String body, String price, String notifyUrl) {
56 | // 签约合作者身份ID
57 | String orderInfo = "partner=" + "\"" + PARTNER + "\"";
58 |
59 | // 签约卖家支付宝账号
60 | orderInfo += "&seller_id=" + "\"" + SELLER + "\"";
61 |
62 | // 商户网站唯一订单号
63 |
64 | orderInfo += "&out_trade_no=" + "\"" + orderId + "\"";
65 |
66 | // 商品名称
67 | orderInfo += "&subject=" + "\"" + subject + "\"";
68 |
69 | // 商品详情
70 | orderInfo += "&body=" + "\"" + body + "\"";
71 |
72 | // 商品金额
73 | orderInfo += "&total_fee=" + "\"" + price + "\"";
74 |
75 | // 服务器异步通知页面路径
76 | orderInfo += "¬ify_url=" + "\"" + notifyUrl
77 | + "\"";
78 |
79 | // 服务接口名称, 固定值
80 | orderInfo += "&service=\"mobile.securitypay.pay\"";
81 |
82 | // 支付类型, 固定值
83 | orderInfo += "&payment_type=\"1\"";
84 |
85 | // 参数编码, 固定值
86 | orderInfo += "&_input_charset=\"utf-8\"";
87 |
88 | // 设置未付款交易的超时时间
89 | // 默认30分钟,一旦超时,该笔交易就会自动被关闭。
90 | // 取值范围:1m~15d。
91 | // m-分钟,h-小时,d-天,1c-当天(无论交易何时创建,都在0点关闭)。
92 | // 该参数数值不接受小数点,如1.5h,可转换为90m。
93 | orderInfo += "&it_b_pay=\"30m\"";
94 |
95 | // extern_token为经过快登授权获取到的alipay_open_id,带上此参数用户将使用授权的账户进行支付
96 | // orderInfo += "&extern_token=" + "\"" + extern_token + "\"";
97 |
98 | // 支付宝处理完请求后,当前页面跳转到商户指定页面的路径,可空
99 | orderInfo += "&return_url=\"m.alipay.com\"";
100 |
101 | // 调用银行卡支付,需配置此参数,参与签名, 固定值 (需要签约《无线银行卡快捷支付》才能使用)
102 | // orderInfo += "&paymethod=\"expressGateway\"";
103 |
104 | return orderInfo;
105 | }
106 | /**
107 | * sign the order info. 对订单信息进行签名
108 | *
109 | * @param content 待签名订单信息
110 | */
111 | private static String sign(String content) {
112 | return SignUtils.sign(content, RSA_PRIVATE);
113 | }
114 |
115 | /**
116 | * get the sign type we use. 获取签名方式
117 | */
118 | private static String getSignType() {
119 | return "sign_type=\"RSA\"";
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/app/src/main/java/com/syhd/payandroid/weixin/WXPay.java:
--------------------------------------------------------------------------------
1 | package com.syhd.payandroid.weixin;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 |
6 | import com.tencent.mm.sdk.constants.Build;
7 | import com.tencent.mm.sdk.modelpay.PayReq;
8 | import com.tencent.mm.sdk.openapi.IWXAPI;
9 | import com.tencent.mm.sdk.openapi.WXAPIFactory;
10 |
11 | import org.json.JSONException;
12 | import org.json.JSONObject;
13 |
14 | /**
15 | * 微信支付
16 | * Created by tsy on 16/6/1.
17 | */
18 | public class WXPay {
19 |
20 | private static WXPay mWXPay;
21 | private IWXAPI mWXApi;
22 | private String mPayParam;
23 | private WXPayResultCallBack mCallback;
24 |
25 | public static final int NO_OR_LOW_WX = 1; //未安装微信或微信版本过低
26 | public static final int ERROR_PAY_PARAM = 2; //支付参数错误
27 | public static final int ERROR_PAY = 3; //支付失败
28 |
29 | public interface WXPayResultCallBack {
30 | void onSuccess(); //支付成功
31 | void onError(int error_code); //支付失败
32 | void onCancel(); //支付取消
33 | }
34 |
35 | public WXPay(Context context, String wx_appid) {
36 | mWXApi = WXAPIFactory.createWXAPI(context, null);
37 | mWXApi.registerApp(wx_appid);
38 | }
39 |
40 | public static void init(Context context, String wx_appid) {
41 | if(mWXPay == null) {
42 | mWXPay = new WXPay(context, wx_appid);
43 | }
44 | }
45 | public static WXPay getInstance(){
46 | return mWXPay;
47 | }
48 |
49 | public IWXAPI getWXApi() {
50 | return mWXApi;
51 | }
52 | /**
53 | * 发起微信支付
54 | */
55 | public void doPay(String pay_param, WXPayResultCallBack callback) {
56 | mPayParam = pay_param;
57 | mCallback = callback;
58 |
59 | if(!check()) {
60 | if(mCallback != null) {
61 | mCallback.onError(NO_OR_LOW_WX);
62 | }
63 | return;
64 | }
65 |
66 | JSONObject param = null;
67 | try {
68 | param = new JSONObject(mPayParam);
69 | } catch (JSONException e) {
70 | e.printStackTrace();
71 | if(mCallback != null) {
72 | mCallback.onError(ERROR_PAY_PARAM);
73 | }
74 | return;
75 | }
76 | if(param == null || TextUtils.isEmpty(param.optString("appid")) || TextUtils.isEmpty(param.optString("partnerid"))
77 | || TextUtils.isEmpty(param.optString("prepayid")) || TextUtils.isEmpty(param.optString("package")) ||
78 | TextUtils.isEmpty(param.optString("noncestr")) || TextUtils.isEmpty(param.optString("timestamp")) ||
79 | TextUtils.isEmpty(param.optString("sign"))) {
80 | if(mCallback != null) {
81 | mCallback.onError(ERROR_PAY_PARAM);
82 | }
83 | return;
84 | }
85 |
86 | PayReq req = new PayReq();
87 | req.appId = param.optString("appid");
88 | req.partnerId = param.optString("partnerid");
89 | req.prepayId = param.optString("prepayid");
90 | req.packageValue = param.optString("package");
91 | req.nonceStr = param.optString("noncestr");
92 | req.timeStamp = param.optString("timestamp");
93 | req.sign = param.optString("sign");
94 |
95 | mWXApi.sendReq(req);
96 | }
97 |
98 | //支付回调响应
99 | public void onResp(int error_code) {
100 | if(mCallback == null) {
101 | return;
102 | }
103 |
104 | if(error_code == 0) { //成功
105 | mCallback.onSuccess();
106 | } else if(error_code == -1) { //错误
107 | mCallback.onError(ERROR_PAY);
108 | } else if(error_code == -2) { //取消
109 | mCallback.onCancel();
110 | }
111 |
112 | mCallback = null;
113 | }
114 |
115 | //检测是否支持微信支付
116 | private boolean check() {
117 | return mWXApi.isWXAppInstalled() && mWXApi.getWXAppSupportAPI() >= Build.PAY_SUPPORTED_SDK_INT;
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/app/src/main/java/com/syhd/payandroid/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.syhd.payandroid;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import com.syhd.payandroid.alipay.client.Alipay;
10 | import com.syhd.payandroid.alipay.server.AlipayServer;
11 | import com.syhd.payandroid.net.HttpUtils;
12 | import com.syhd.payandroid.net.StringCallback;
13 | import com.syhd.payandroid.weixin.WXPay;
14 |
15 | import java.text.SimpleDateFormat;
16 | import java.util.Date;
17 | import java.util.Locale;
18 | import java.util.Random;
19 |
20 | public class MainActivity extends AppCompatActivity {
21 |
22 | private String TAG = "MainActivity";
23 | private Button alipayBtn;
24 | private Button wxpayBtn;
25 |
26 | /**
27 | * 替换自己的支付宝回调地址
28 | */
29 | private String alipaycallback = "http://callbackurl";
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_main);
35 | /**
36 | * 支付宝支付
37 | */
38 | alipayBtn = (Button) findViewById(R.id.alipay);
39 | alipayBtn.setOnClickListener(new View.OnClickListener() {
40 | @Override
41 | public void onClick(View view) {
42 | //在服务器生成订单信息
43 | String payInfo = AlipayServer.getPayInfo(getOutTradeNo(), "商品名称", "商品描述", "1", alipaycallback);
44 | //客户端调起支付宝支付
45 | Alipay alipay = new Alipay(MainActivity.this, payInfo, new Alipay.AlipayResultCallBack() {
46 | @Override
47 | public void onSuccess() {
48 | Log.d(TAG, "支付成功");
49 | }
50 |
51 | @Override
52 | public void onDealing() {
53 | Log.d(TAG, "支付中");
54 | }
55 |
56 | @Override
57 | public void onError(int error_code) {
58 | Log.d(TAG, "支付错误" + error_code);
59 | }
60 |
61 | @Override
62 | public void onCancel() {
63 | Log.d(TAG, "支付取消");
64 | }
65 | });
66 | alipay.doPay();
67 | }
68 | });
69 |
70 | /**
71 | * 微信支付
72 | * 微信支付常见坑
73 | * 1.微信开放平台的包名和签名是否和本地的一致
74 | * 2.服务器能拿到prepare_id,还是返回-1,查看调起支付接口时的签名是否计算正确
75 | * 3.能调起支付,没有返回消息的,请查看自己项目包下是否有(wxapi.WXPayEntryActivity)
76 | * 4.本地调试时一定要使用正式签名文件进行调试,否则是调不起微信支付窗口的
77 | * 5.网络上遇到说微信缓存会影响返回-1的,目前没有遇到过
78 | */
79 | wxpayBtn = (Button) findViewById(R.id.wxpay);
80 | wxpayBtn.setOnClickListener(new View.OnClickListener() {
81 | @Override
82 | public void onClick(View view) {
83 | /**请求自己的服务器获取支付参数*/
84 | String url = "http://wxpay.weixin.qq.com/pub_v2/app/app_pay.php?plat=android";
85 |
86 | /**
87 | * {"appid":"wxb4ba3c02aa476ea1","partnerid":"1305176001","package":"Sign=WXPay","noncestr":"d86b800063efb51837c1fd6f6c806acc","timestamp":1468313097,"prepayid":"wx20160712164457dddf6add490242369966","sign":"E6FFA6E8A39589FE4C5A51592095398A"}
88 | */
89 | HttpUtils.httpGet(MainActivity.this, url, new StringCallback() {
90 | @Override
91 | public void onError(String request) {
92 |
93 | }
94 |
95 | @Override
96 | public void onResponse(String response) {
97 | Log.i(TAG, response);
98 | WXPay wxpay = new WXPay(MainActivity.this, "wxb4ba3c02aa476ea1");
99 | wxpay.doPay(response, new WXPay.WXPayResultCallBack() {
100 | @Override
101 | public void onSuccess() {
102 | Log.d(TAG, "支付成功");
103 | }
104 |
105 | @Override
106 | public void onError(int error_code) {
107 | Log.d(TAG, "支付失败" + error_code);
108 | }
109 |
110 | @Override
111 | public void onCancel() {
112 | Log.d(TAG, "支付取消");
113 | }
114 | });
115 | }
116 | });
117 | }
118 | });
119 |
120 | }
121 |
122 | /**
123 | * get the out_trade_no for an order. 生成商户订单号,该值在商户端应保持唯一(可自定义格式规范)
124 | */
125 | private String getOutTradeNo() {
126 | SimpleDateFormat format = new SimpleDateFormat("MMddHHmmss", Locale.getDefault());
127 | Date date = new Date();
128 | String key = format.format(date);
129 |
130 | Random r = new Random();
131 | key = key + r.nextInt();
132 | key = key.substring(0, 15);
133 | return key;
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/syhd/payandroid/alipay/server/Base64.java:
--------------------------------------------------------------------------------
1 | package com.syhd.payandroid.alipay.server;
2 |
3 | public final class Base64 {
4 |
5 | private static final int BASELENGTH = 128;
6 | private static final int LOOKUPLENGTH = 64;
7 | private static final int TWENTYFOURBITGROUP = 24;
8 | private static final int EIGHTBIT = 8;
9 | private static final int SIXTEENBIT = 16;
10 | private static final int FOURBYTE = 4;
11 | private static final int SIGN = -128;
12 | private static char PAD = '=';
13 | private static byte[] base64Alphabet = new byte[BASELENGTH];
14 | private static char[] lookUpBase64Alphabet = new char[LOOKUPLENGTH];
15 |
16 | static {
17 | for (int i = 0; i < BASELENGTH; ++i) {
18 | base64Alphabet[i] = -1;
19 | }
20 | for (int i = 'Z'; i >= 'A'; i--) {
21 | base64Alphabet[i] = (byte) (i - 'A');
22 | }
23 | for (int i = 'z'; i >= 'a'; i--) {
24 | base64Alphabet[i] = (byte) (i - 'a' + 26);
25 | }
26 |
27 | for (int i = '9'; i >= '0'; i--) {
28 | base64Alphabet[i] = (byte) (i - '0' + 52);
29 | }
30 |
31 | base64Alphabet['+'] = 62;
32 | base64Alphabet['/'] = 63;
33 |
34 | for (int i = 0; i <= 25; i++) {
35 | lookUpBase64Alphabet[i] = (char) ('A' + i);
36 | }
37 |
38 | for (int i = 26, j = 0; i <= 51; i++, j++) {
39 | lookUpBase64Alphabet[i] = (char) ('a' + j);
40 | }
41 |
42 | for (int i = 52, j = 0; i <= 61; i++, j++) {
43 | lookUpBase64Alphabet[i] = (char) ('0' + j);
44 | }
45 | lookUpBase64Alphabet[62] = (char) '+';
46 | lookUpBase64Alphabet[63] = (char) '/';
47 |
48 | }
49 |
50 | private static boolean isWhiteSpace(char octect) {
51 | return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9);
52 | }
53 |
54 | private static boolean isPad(char octect) {
55 | return (octect == PAD);
56 | }
57 |
58 | private static boolean isData(char octect) {
59 | return (octect < BASELENGTH && base64Alphabet[octect] != -1);
60 | }
61 |
62 | /**
63 | * Encodes hex octects into Base64
64 | *
65 | * @param binaryData
66 | * Array containing binaryData
67 | * @return Encoded Base64 array
68 | */
69 | public static String encode(byte[] binaryData) {
70 |
71 | if (binaryData == null) {
72 | return null;
73 | }
74 |
75 | int lengthDataBits = binaryData.length * EIGHTBIT;
76 | if (lengthDataBits == 0) {
77 | return "";
78 | }
79 |
80 | int fewerThan24bits = lengthDataBits % TWENTYFOURBITGROUP;
81 | int numberTriplets = lengthDataBits / TWENTYFOURBITGROUP;
82 | int numberQuartet = fewerThan24bits != 0 ? numberTriplets + 1
83 | : numberTriplets;
84 | char encodedData[] = null;
85 |
86 | encodedData = new char[numberQuartet * 4];
87 |
88 | byte k = 0, l = 0, b1 = 0, b2 = 0, b3 = 0;
89 |
90 | int encodedIndex = 0;
91 | int dataIndex = 0;
92 |
93 | for (int i = 0; i < numberTriplets; i++) {
94 | b1 = binaryData[dataIndex++];
95 | b2 = binaryData[dataIndex++];
96 | b3 = binaryData[dataIndex++];
97 |
98 | l = (byte) (b2 & 0x0f);
99 | k = (byte) (b1 & 0x03);
100 |
101 | byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2)
102 | : (byte) ((b1) >> 2 ^ 0xc0);
103 | byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4)
104 | : (byte) ((b2) >> 4 ^ 0xf0);
105 | byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6)
106 | : (byte) ((b3) >> 6 ^ 0xfc);
107 |
108 | encodedData[encodedIndex++] = lookUpBase64Alphabet[val1];
109 | encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)];
110 | encodedData[encodedIndex++] = lookUpBase64Alphabet[(l << 2) | val3];
111 | encodedData[encodedIndex++] = lookUpBase64Alphabet[b3 & 0x3f];
112 | }
113 |
114 | // form integral number of 6-bit groups
115 | if (fewerThan24bits == EIGHTBIT) {
116 | b1 = binaryData[dataIndex];
117 | k = (byte) (b1 & 0x03);
118 |
119 | byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2)
120 | : (byte) ((b1) >> 2 ^ 0xc0);
121 | encodedData[encodedIndex++] = lookUpBase64Alphabet[val1];
122 | encodedData[encodedIndex++] = lookUpBase64Alphabet[k << 4];
123 | encodedData[encodedIndex++] = PAD;
124 | encodedData[encodedIndex++] = PAD;
125 | } else if (fewerThan24bits == SIXTEENBIT) {
126 | b1 = binaryData[dataIndex];
127 | b2 = binaryData[dataIndex + 1];
128 | l = (byte) (b2 & 0x0f);
129 | k = (byte) (b1 & 0x03);
130 |
131 | byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2)
132 | : (byte) ((b1) >> 2 ^ 0xc0);
133 | byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4)
134 | : (byte) ((b2) >> 4 ^ 0xf0);
135 |
136 | encodedData[encodedIndex++] = lookUpBase64Alphabet[val1];
137 | encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)];
138 | encodedData[encodedIndex++] = lookUpBase64Alphabet[l << 2];
139 | encodedData[encodedIndex++] = PAD;
140 | }
141 |
142 | return new String(encodedData);
143 | }
144 |
145 | /**
146 | * Decodes Base64 data into octects
147 | *
148 | * @param encoded
149 | * string containing Base64 data
150 | * @return Array containind decoded data.
151 | */
152 | public static byte[] decode(String encoded) {
153 |
154 | if (encoded == null) {
155 | return null;
156 | }
157 |
158 | char[] base64Data = encoded.toCharArray();
159 | // remove white spaces
160 | int len = removeWhiteSpace(base64Data);
161 |
162 | if (len % FOURBYTE != 0) {
163 | return null;// should be divisible by four
164 | }
165 |
166 | int numberQuadruple = (len / FOURBYTE);
167 |
168 | if (numberQuadruple == 0) {
169 | return new byte[0];
170 | }
171 |
172 | byte decodedData[] = null;
173 | byte b1 = 0, b2 = 0, b3 = 0, b4 = 0;
174 | char d1 = 0, d2 = 0, d3 = 0, d4 = 0;
175 |
176 | int i = 0;
177 | int encodedIndex = 0;
178 | int dataIndex = 0;
179 | decodedData = new byte[(numberQuadruple) * 3];
180 |
181 | for (; i < numberQuadruple - 1; i++) {
182 |
183 | if (!isData((d1 = base64Data[dataIndex++]))
184 | || !isData((d2 = base64Data[dataIndex++]))
185 | || !isData((d3 = base64Data[dataIndex++]))
186 | || !isData((d4 = base64Data[dataIndex++]))) {
187 | return null;
188 | }// if found "no data" just return null
189 |
190 | b1 = base64Alphabet[d1];
191 | b2 = base64Alphabet[d2];
192 | b3 = base64Alphabet[d3];
193 | b4 = base64Alphabet[d4];
194 |
195 | decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
196 | decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
197 | decodedData[encodedIndex++] = (byte) (b3 << 6 | b4);
198 | }
199 |
200 | if (!isData((d1 = base64Data[dataIndex++]))
201 | || !isData((d2 = base64Data[dataIndex++]))) {
202 | return null;// if found "no data" just return null
203 | }
204 |
205 | b1 = base64Alphabet[d1];
206 | b2 = base64Alphabet[d2];
207 |
208 | d3 = base64Data[dataIndex++];
209 | d4 = base64Data[dataIndex++];
210 | if (!isData((d3)) || !isData((d4))) {// Check if they are PAD characters
211 | if (isPad(d3) && isPad(d4)) {
212 | if ((b2 & 0xf) != 0)// last 4 bits should be zero
213 | {
214 | return null;
215 | }
216 | byte[] tmp = new byte[i * 3 + 1];
217 | System.arraycopy(decodedData, 0, tmp, 0, i * 3);
218 | tmp[encodedIndex] = (byte) (b1 << 2 | b2 >> 4);
219 | return tmp;
220 | } else if (!isPad(d3) && isPad(d4)) {
221 | b3 = base64Alphabet[d3];
222 | if ((b3 & 0x3) != 0)// last 2 bits should be zero
223 | {
224 | return null;
225 | }
226 | byte[] tmp = new byte[i * 3 + 2];
227 | System.arraycopy(decodedData, 0, tmp, 0, i * 3);
228 | tmp[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
229 | tmp[encodedIndex] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
230 | return tmp;
231 | } else {
232 | return null;
233 | }
234 | } else { // No PAD e.g 3cQl
235 | b3 = base64Alphabet[d3];
236 | b4 = base64Alphabet[d4];
237 | decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
238 | decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
239 | decodedData[encodedIndex++] = (byte) (b3 << 6 | b4);
240 |
241 | }
242 |
243 | return decodedData;
244 | }
245 |
246 | /**
247 | * remove WhiteSpace from MIME containing encoded Base64 data.
248 | *
249 | * @param data
250 | * the byte array of base64 data (with WS)
251 | * @return the new length
252 | */
253 | private static int removeWhiteSpace(char[] data) {
254 | if (data == null) {
255 | return 0;
256 | }
257 |
258 | // count characters that's not whitespace
259 | int newSize = 0;
260 | int len = data.length;
261 | for (int i = 0; i < len; i++) {
262 | if (!isWhiteSpace(data[i])) {
263 | data[newSize++] = data[i];
264 | }
265 | }
266 | return newSize;
267 | }
268 | }
269 |
--------------------------------------------------------------------------------