Android学习笔记_69_android⽀付宝之⽹页⽀付和快捷⽀付参考资料:
转
--- ⽹页⽀付
张柏芝被多少人日过wappaygw.alipay/service/rest.htm?
req_data=
<direct_trade_create_req>
<subject>12121212</subject>
<out_trade_no>12121021</out_trade_no>
<total_fee>1</total_fee>
<seller_account_name>che12121</seller_account_name>
<notify_url>www.alipay/waptest0504/servlet/NotifyReceiver</notify_url>
<out_user>outID123</out_user>
<merchant_url>www.alipay</merchant_url>
<pay_expire>10</pay_expire>
</direct_trade_create_req>
&service=ate.direct
&sec_id=0001&partner=12112
&req_id=11121212
&sign=bDfw5%2Bctc3pxzl7emPxqOod4EiPu3BkE0 Um54g4whHT22CwLbOn1gzyE%2BU5SIleGPke2rNQ%3D
&format=xml
&v=2.0
⽹页⽀付拿这服务器返回的地址,通过webview直接请求就可以
public class AlipayWebActivity extends Activity {
private WebView mWebView;
private ProgressDialog mProgressDialog;
private static final String TAG = "AlipayWebActivity";
protected static final int PAY_SUCCESS = 20;
protected static final int LOAD_FINISH_CODE = 40;
private static final int DEFAULT_CODE = 50;
private ImageView quitImageView;
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.web);
quitImageView = (ImageView) findViewById(R.id.iv_quit);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.setBackgroundColor(0);
initial();
quitImageView.setOnClickListener(new MyOnClickListener());
}
@SuppressLint({ "SetJavaScriptEnabled", "HandlerLeak" })
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void initial() {
String url = getIntent().getStringExtra("url");
LogUtil.i(TAG, url);
WebSettings webSettings = Settings();
webSettings.setJavaScriptEnabled(true);
mWebView.setFocusable(true);
webSettings.setBuiltInZoomControls(true);
mWebView.setScrollBarStyle(0);
if (MobileVersion()>11) {
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int newProgress) {
LogUtil.i(TAG, "newProgress: " + newProgress);
if (newProgress == 100 && mProgressDialog!=null) {
mProgressDialog.dismiss();
}
}
});
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
LogUtil.i(TAG, "URL : " + url);
LogUtil.i(TAG, "URL : " + ains("&cmd=success&"));
loadUrl(view, url);
return true;//停⽌在当前界⾯
}
public void onPageFinished(WebView view, String url) {
LogUtil.i(TAG, "onPageFinished" + url);
//trade_status : TRADE_FINISHED,成功之后处理
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
LogUtil.i(TAG, "onPageStarted" + url);
}
});
loadUrl(mWebView, url);
}
@SuppressLint("HandlerLeak")
private Handler mUihandler = new Handler() {
public void handleMessage(Message msg) {曾轶可背景
switch (msg.what) {
case PAY_SUCCESS:
clearCache();
break;
case LOAD_FINISH_CODE:
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
break;
case DEFAULT_CODE:
showProgressDialog(AlipayWebActivity.this,
R.string.dialog_loading);
}
super.handleMessage(msg);
}
};
private void loadUrl(final WebView webView, final String url) {
mUihandler.sendEmptyMessage(DEFAULT_CODE);
webView.loadUrl(url);
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
LogUtil.i(TAG, "can goback:" + mWebView.canGoBack());
if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
英雄联盟自动关闭return true;
} else if (keyCode == KeyEvent.KEYCODE_BACK) {
onBackPressed();
return true;
}
KeyDown(keyCode, event);
}
public void showProgressDialog(Context context, int message) {
if (mProgressDialog == null) {
mProgressDialog = new ProgressDialog(context);
mProgressDialog.Text(message));
mProgressDialog.show();
}
}
private void clearCache() {
mWebView.clearCache(true);
mWebView.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
finish();
}
private class MyOnClickListener implements OnClickListener{
@Override
public void onClick(View v) {
int id = v.getId();
if (id==R.id.iv_quit) {
finish();
}
}
}
}
--- 快捷⽀付
1、公钥,密钥,签名在服务器端完成,⽐放在客户端安全。
2、报4000 4100⼀般就是参数出现错误,仔细⽐对,如果参数都没问题,很有可能是sign也就是签名没有通过。签名之后不能对已经签名的字符串做任何修改,因为⽀付宝需要解密的。
3、如果报服务器繁忙,然后打印出参数⾮法的警告信息时, Instance("RSA", "BC") 可以解决。
4、sign签名要utf-8格式。
/*
* Copyright (C) 2010 The MobileSecurePay Project
* All right reserved.
* author: shiqun.shi@alipay
*/
ame.dudu.payment.alipay;
import android.app.Activity;
t.DialogInterface;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;
import com.alipay.android.app.sdk.AliPay;
ame.dudu.payment.R;
ame.dudu.payment.ui.FactoryUtil;
ame.dudu.payment.util.BaseDialogUtil;
ame.dudu.payment.util.LogUtil;
public class AlipayUtil {
洗发水什么牌子好private static String TAG = "AlipayUtil";
private Activity activity;
private String order;
private static final int RQF_PAY = 1;
private static final int RQF_LOGIN = 2;
public AlipayUtil(Activity activity, String order) {
this.activity = activity;
LogUtil.i(TAG, String() + " "
+ MainLooper().toString());
白健恩}
public void pay() {
// 根据订单信息开始进⾏⽀付
try {
new Thread() {
public void run() {
AliPay alipay = new AliPay(activity, mHandler);
String result = alipay.pay(order);
Message msg = new Message();
msg.what = RQF_PAY;
msg.obj = result;
mHandler.sendMessage(msg);
}
}.start();
} catch (Exception ex) {高血压吃什么食物
Toast.makeText(activity, R.string.pay_fail,Toast.LENGTH_SHORT).show();
activity.finish();
}
}
Handler mHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
Result result = new Result((String) msg.obj);
switch (msg.what) {
case RQF_PAY:
case RQF_LOGIN: {
try {
String ret = Result();
result.parseResult();
LogUtil.i(TAG, ret);
LogUtil.i(TAG, "1: " + result.isSignOk + " 2: "
+ + " 3: " + sultStatus);
// 先验签通知
// 1: false 2: 3: 操作成功(9000)
// 验签失败
if (result.isSignOk) {
Toast.makeText(activity, R.string.check_sign_fail, Toast.LENGTH_SHORT).show();
} else {// 验签成功。验签成功后再判断交易状态码
if ("操作成功(9000)".sultStatus)) {// 判断交易状态码,只有9000表⽰交易成功
//成功之后执⾏
});
} else {
Toast.makeText(activity,
"⽀付失败。交易状态码:" + sultStatus,
Toast.LENGTH_SHORT).show();
}
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(activity, R.string.pay_fail, Toast.LENGTH_SHORT).show();
}
}
break;
default:
break;
}
};
};
}
剩下的⽂档⾥⾯都有,只需要处理的是⽀付成功与失败的逻辑。
提交到⽀付宝的订单快捷⽀付:
partner="2088511"&out_trade_no="2014410490790001211"&subject="⽀付0.01元"&body="⽀付0.01元"&total_fee="0.01"
¬ify_url="http%3A%2F%2F122.32.196.157%3A90%2Freeonse%2Falipaydut"&service="mobile.securitypay.pay"&_input_charset="utf-8"&payment_type="1"&seller_id="2008354621302100"&show_url=""
&it_b_pay="30m"&sign="MPZ8lamKUDgidaIn2KwX%2B6GX4o3BSheEUI2xg3aJa1b%2B1M6VXP%2BaMA3szSBPyl7UYm%2Fdhz8KVuFn5Du057R2lUNQ%2B2nSb3qSXZ6rZcNQ2rCrZ84Kiy3MWFBqlt%2Buq%2FufaCOnGEQyo18NXnm6OGD &sign_type="RSA"
发布评论