-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tangsiyuan
committed
Dec 9, 2016
1 parent
2e46135
commit 4cccb0f
Showing
36 changed files
with
795 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea | ||
.DS_Store | ||
/build | ||
/captures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 24 | ||
buildToolsVersion "24.0.3" | ||
|
||
defaultConfig { | ||
applicationId "com.tsy.paydemo" | ||
minSdkVersion 11 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(include: ['*.jar'], dir: 'libs') | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:24.2.1' | ||
|
||
compile project(':pay_android_sdk') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/tsy/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# 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 *; | ||
#} |
2 changes: 1 addition & 1 deletion
2
...om/ci123/service/pay/ApplicationTest.java → ...java/com/tsy/paydemo/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.tsy.paydemo"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name="com.tsy.paydemo.MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<!-- 微信支付 --> | ||
<activity | ||
android:name="com.tsy.sdk.pay.weixin.WXPayCallbackActivity" | ||
android:configChanges="orientation|keyboardHidden|navigation|screenSize" | ||
android:launchMode="singleTop" | ||
android:theme="@android:style/Theme.Translucent.NoTitleBar" /> | ||
|
||
<activity-alias | ||
android:name=".wxapi.WXPayEntryActivity" | ||
android:exported="true" | ||
android:targetActivity="com.tsy.sdk.pay.weixin.WXPayCallbackActivity" /> | ||
|
||
<!-- 支付宝支付 --> | ||
<activity | ||
android:name="com.alipay.sdk.app.H5PayActivity" | ||
android:configChanges="orientation|keyboardHidden|navigation" | ||
android:exported="false" | ||
android:screenOrientation="behind"></activity> | ||
<activity | ||
android:name="com.alipay.sdk.auth.AuthActivity" | ||
android:configChanges="orientation|keyboardHidden|navigation" | ||
android:exported="false" | ||
android:screenOrientation="behind"></activity> | ||
|
||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
package com.tsy.paydemo; | ||
|
||
import android.content.ClipboardManager; | ||
import android.content.Context; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.text.TextUtils; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.Toast; | ||
|
||
import com.tsy.sdk.pay.PayUtils; | ||
import com.tsy.sdk.pay.alipay.Alipay; | ||
import com.tsy.sdk.pay.weixin.WXPay; | ||
|
||
public class MainActivity extends AppCompatActivity implements View.OnClickListener { | ||
|
||
private EditText editWXParam, editAlipayParam; | ||
private Button btnWXPay, btnAlipay, btnWXClear, btnWXPaste, btnAliPayClear, btnAliPayPaste, btnGetIp; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
editAlipayParam = (EditText)findViewById(R.id.editAlipayParam); | ||
editWXParam = (EditText)findViewById(R.id.editWXParam); | ||
btnAlipay = (Button)findViewById(R.id.btnAliPay); | ||
btnWXPay = (Button)findViewById(R.id.btnWXPay); | ||
btnWXClear = (Button)findViewById(R.id.btnWXClear); | ||
btnWXPaste = (Button)findViewById(R.id.btnWXPaste); | ||
btnAliPayClear = (Button)findViewById(R.id.btnAliPayClear); | ||
btnAliPayPaste = (Button)findViewById(R.id.btnAliPayPaste); | ||
btnGetIp = (Button)findViewById(R.id.btnGetIp); | ||
|
||
btnAlipay.setOnClickListener(this); | ||
btnWXPay.setOnClickListener(this); | ||
btnWXClear.setOnClickListener(this); | ||
btnWXPaste.setOnClickListener(this); | ||
btnAliPayClear.setOnClickListener(this); | ||
btnAliPayPaste.setOnClickListener(this); | ||
btnGetIp.setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
switch (v.getId()) { | ||
case R.id.btnWXPay: | ||
String wx_pay_param = editWXParam.getText().toString(); | ||
if(TextUtils.isEmpty(wx_pay_param)) { | ||
Toast.makeText(getApplication(), "请输入参数", Toast.LENGTH_SHORT).show(); | ||
return; | ||
} | ||
doWXPay(wx_pay_param); | ||
break; | ||
|
||
case R.id.btnWXClear: | ||
editWXParam.setText(""); | ||
break; | ||
|
||
case R.id.btnWXPaste: | ||
ClipboardManager cbm=(ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); | ||
editWXParam.setText(cbm.getText()); | ||
break; | ||
|
||
case R.id.btnAliPay: | ||
String alipay_pay_param = editAlipayParam.getText().toString(); | ||
if(TextUtils.isEmpty(alipay_pay_param)) { | ||
Toast.makeText(getApplication(), "请输入参数", Toast.LENGTH_SHORT).show(); | ||
return; | ||
} | ||
doAlipay(alipay_pay_param); | ||
break; | ||
|
||
case R.id.btnAliPayClear: | ||
editAlipayParam.setText(""); | ||
break; | ||
|
||
case R.id.btnAliPayPaste: | ||
ClipboardManager cbm2=(ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); | ||
editAlipayParam.setText(cbm2.getText()); | ||
break; | ||
|
||
case R.id.btnGetIp: | ||
String ip = PayUtils.getIpAddress(); | ||
if(ip != null) { | ||
Toast.makeText(getApplication(), ip, Toast.LENGTH_SHORT).show(); | ||
} else { | ||
Toast.makeText(getApplication(), "获取ip失败", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
|
||
/** | ||
* 支付宝支付 | ||
* @param pay_param 支付服务生成的支付参数 | ||
*/ | ||
private void doAlipay(String pay_param) { | ||
new Alipay(this, pay_param, new Alipay.AlipayResultCallBack() { | ||
@Override | ||
public void onSuccess() { | ||
Toast.makeText(getApplication(), "支付成功", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
@Override | ||
public void onDealing() { | ||
Toast.makeText(getApplication(), "支付处理中...", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
@Override | ||
public void onError(int error_code) { | ||
switch (error_code) { | ||
case Alipay.ERROR_RESULT: | ||
Toast.makeText(getApplication(), "支付失败:支付结果解析错误", Toast.LENGTH_SHORT).show(); | ||
break; | ||
|
||
case Alipay.ERROR_NETWORK: | ||
Toast.makeText(getApplication(), "支付失败:网络连接错误", Toast.LENGTH_SHORT).show(); | ||
break; | ||
|
||
case Alipay.ERROR_PAY: | ||
Toast.makeText(getApplication(), "支付错误:支付码支付失败", Toast.LENGTH_SHORT).show(); | ||
break; | ||
|
||
default: | ||
Toast.makeText(getApplication(), "支付错误", Toast.LENGTH_SHORT).show(); | ||
break; | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void onCancel() { | ||
Toast.makeText(getApplication(), "支付取消", Toast.LENGTH_SHORT).show(); | ||
} | ||
}).doPay(); | ||
} | ||
|
||
/** | ||
* 微信支付 | ||
* @param pay_param 支付服务生成的支付参数 | ||
*/ | ||
private void doWXPay(String pay_param) { | ||
String wx_appid = "wx6b69bdbf2adca4f8"; //替换为自己的appid | ||
WXPay.init(getApplicationContext(), wx_appid); //要在支付前调用 | ||
WXPay.getInstance().doPay(pay_param, new WXPay.WXPayResultCallBack() { | ||
@Override | ||
public void onSuccess() { | ||
Toast.makeText(getApplication(), "支付成功", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
@Override | ||
public void onError(int error_code) { | ||
switch (error_code) { | ||
case WXPay.NO_OR_LOW_WX: | ||
Toast.makeText(getApplication(), "未安装微信或微信版本过低", Toast.LENGTH_SHORT).show(); | ||
break; | ||
|
||
case WXPay.ERROR_PAY_PARAM: | ||
Toast.makeText(getApplication(), "参数错误", Toast.LENGTH_SHORT).show(); | ||
break; | ||
|
||
case WXPay.ERROR_PAY: | ||
Toast.makeText(getApplication(), "支付失败", Toast.LENGTH_SHORT).show(); | ||
break; | ||
} | ||
} | ||
|
||
@Override | ||
public void onCancel() { | ||
Toast.makeText(getApplication(), "支付取消", Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.