安卓支付宝支付详解与一些遇到的问题

       首先说明一下   支付宝支付安卓用的是快捷支付,下载地址是https://b.alipay.com/order/techService.htm     支付宝移动接入地址https://b.alipay.com/。支付宝开放平台文档是用来调用支付宝的API如登陆账号、查询余额等,和支付没有半毛线的关系。好了说完这些咱们就进入正题。

      下载好支付宝快捷支付的压缩包,解压下找到安卓客户端的demo,导入工程中。咱们只用到一个类,就是PayDemoActivity,将里面的public static final String PARTNER=“”;public static final String SELLER =“”;public static final String RSA_PRIVATE =“'";三个值写好。第一个值是商户id,地址https://b.alipay.com/order/pidAndKey.htm去找。第二个是商户账号,说明一下,第一个和第二个必须一致,否则无法调用,会报系统繁忙,请稍后再试,第三个是你自己生成的私钥。有这三个参数就可以调用支付宝支付了。

      秘钥生成文档已经说的很详细了,可以去下载,如果找不到下载的地方,我就把下好的压缩包上传到这里,大家去这里下载下就好,地址http://download.csdn.net/detail/u012303938/8374651  ps:秘钥路径不能有中文,否则只能生成私钥,公钥和PKCS8无法生成

      接下来就是说一些支付宝支付遇到的问题,

   1.提示系统繁忙,请稍后再试(ALI69)你的商户idPARTNER有问题,

   2.提示系统繁忙,请稍后再试(ALI129)你的商户账号SELLER有问题,记住PARTNER与SELLER必须一致。

   3.提示系统繁忙,请稍后再试(ALI59)你支付的钱最低是0.01,不能写成0.00或其他负值。

   4.报如下错

01-19 09:17:15.367: W/System.err(24886): java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
01-19 09:17:15.373: W/System.err(24886): <span style="white-space:pre">	</span>at org.apache.harmony.xnet.provider.jsse.OpenSSLRSAKeyFactory.engineGeneratePrivate(OpenSSLRSAKeyFactory.java:77)
01-19 09:17:15.373: W/System.err(24886): <span style="white-space:pre">	</span>at java.security.KeyFactory.generatePrivate(KeyFactory.java:186)
01-19 09:17:15.373: W/System.err(24886): <span style="white-space:pre">	</span>at com.alipay.sdk.pay.demo.SignUtils.sign(SignUtils.java:20)
01-19 09:17:15.373: W/System.err(24886): <span style="white-space:pre">	</span>at com.alipay.sdk.pay.demo.PayDemoActivity.sign(PayDemoActivity.java:236)
01-19 09:17:15.374: W/System.err(24886): <span style="white-space:pre">	</span>at com.alipay.sdk.pay.demo.PayDemoActivity.pay(PayDemoActivity.java:94)
01-19 09:17:15.374: W/System.err(24886): <span style="white-space:pre">	</span>at java.lang.reflect.Method.invokeNative(Native Method)
01-19 09:17:15.375: W/System.err(24886): <span style="white-space:pre">	</span>at java.lang.reflect.Method.invoke(Method.java:525)
01-19 09:17:15.375: W/System.err(24886): <span style="white-space:pre">	</span>at android.view.View$1.onClick(View.java:3602)
01-19 09:17:15.375: W/System.err(24886): <span style="white-space:pre">	</span>at android.view.View.performClick(View.java:4227)
01-19 09:17:15.376: W/System.err(24886): <span style="white-space:pre">	</span>at android.view.View$PerformClick.run(View.java:17507)
01-19 09:17:15.377: W/System.err(24886): <span style="white-space:pre">	</span>at android.os.Handler.handleCallback(Handler.java:800)
01-19 09:17:15.377: W/System.err(24886): <span style="white-space:pre">	</span>at android.os.Handler.dispatchMessage(Handler.java:100)
01-19 09:17:15.377: W/System.err(24886): <span style="white-space:pre">	</span>at android.os.Looper.loop(Looper.java:194)
01-19 09:17:15.378: W/System.err(24886): <span style="white-space:pre">	</span>at android.app.ActivityThread.main(ActivityThread.java:5407)
01-19 09:17:15.378: W/System.err(24886): <span style="white-space:pre">	</span>at java.lang.reflect.Method.invokeNative(Native Method)
01-19 09:17:15.378: W/System.err(24886): <span style="white-space:pre">	</span>at java.lang.reflect.Method.invoke(Method.java:525)
01-19 09:17:15.379: W/System.err(24886): <span style="white-space:pre">	</span>at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
01-19 09:17:15.379: W/System.err(24886): <span style="white-space:pre">	</span>at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
01-19 09:17:15.380: W/System.err(24886): <span style="white-space:pre">	</span>at dalvik.system.NativeStart.main(Native Method)
01-19 09:17:15.381: W/System.err(24886): Caused by: java.lang.RuntimeException: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
01-19 09:17:15.383: W/System.err(24886): <span style="white-space:pre">	</span>at org.apache.harmony.xnet.provider.jsse.NativeCrypto.d2i_PKCS8_PRIV_KEY_INFO(Native Method)
01-19 09:17:15.383: W/System.err(24886): <span style="white-space:pre">	</span>at org.apache.harmony.xnet.provider.jsse.OpenSSLRSAKeyFactory.engineGeneratePrivate(OpenSSLRSAKeyFactory.java:73)
01-19 09:17:15.384: W/System.err(24886): <span style="white-space:pre">	</span>... 18 more
01-19 09:17:15.384: D/AndroidRuntime(24886): Shutting down VM
01-19 09:17:15.384: W/dalvikvm(24886): threadid=1: thread exiting with uncaught exception (group=0x40e799a8)
01-19 09:17:15.385: W/dalvikvm(24886): threadid=1: uncaught exception occurred
01-19 09:17:15.385: W/System.err(24886): java.lang.IllegalStateException: Could not execute method of the activity
01-19 09:17:15.386: W/System.err(24886): <span style="white-space:pre">	</span>at android.view.View$1.onClick(View.java:3607)
01-19 09:17:15.387: W/System.err(24886): <span style="white-space:pre">	</span>at android.view.View.performClick(View.java:4227)
01-19 09:17:15.387: W/System.err(24886): <span style="white-space:pre">	</span>at android.view.View$PerformClick.run(View.java:17507)
01-19 09:17:15.388: W/System.err(24886): <span style="white-space:pre">	</span>at android.os.Handler.handleCallback(Handler.java:800)
01-19 09:17:15.389: W/System.err(24886): <span style="white-space:pre">	</span>at android.os.Handler.dispatchMessage(Handler.java:100)
01-19 09:17:15.389: W/System.err(24886): <span style="white-space:pre">	</span>at android.os.Looper.loop(Looper.java:194)
01-19 09:17:15.390: W/System.err(24886): <span style="white-space:pre">	</span>at android.app.ActivityThread.main(ActivityThread.java:5407)
01-19 09:17:15.390: W/System.err(24886): <span style="white-space:pre">	</span>at java.lang.reflect.Method.invokeNative(Native Method)
01-19 09:17:15.392: W/System.err(24886): <span style="white-space:pre">	</span>at java.lang.reflect.Method.invoke(Method.java:525)
01-19 09:17:15.392: W/System.err(24886): <span style="white-space:pre">	</span>at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
01-19 09:17:15.392: W/System.err(24886): <span style="white-space:pre">	</span>at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
01-19 09:17:15.392: W/System.err(24886): <span style="white-space:pre">	</span>at dalvik.system.NativeStart.main(Native Method)
01-19 09:17:15.393: W/System.err(24886): Caused by: java.lang.reflect.InvocationTargetException
01-19 09:17:15.395: W/System.err(24886): <span style="white-space:pre">	</span>at java.lang.reflect.Method.invokeNative(Native Method)
01-19 09:17:15.396: W/System.err(24886): <span style="white-space:pre">	</span>at java.lang.reflect.Method.invoke(Method.java:525)
01-19 09:17:15.396: W/System.err(24886): <span style="white-space:pre">	</span>at android.view.View$1.onClick(View.java:3602)
01-19 09:17:15.396: W/System.err(24886): <span style="white-space:pre">	</span>... 11 more
01-19 09:17:15.397: W/System.err(24886): Caused by: java.lang.NullPointerException
01-19 09:17:15.398: W/System.err(24886): <span style="white-space:pre">	</span>at libcore.net.UriCodec.encode(UriCodec.java:132)
01-19 09:17:15.398: W/System.err(24886): <span style="white-space:pre">	</span>at java.net.URLEncoder.encode(URLEncoder.java:57)
01-19 09:17:15.399: W/System.err(24886): <span style="white-space:pre">	</span>at com.alipay.sdk.pay.demo.PayDemoActivity.pay(PayDemoActivity.java:97)
01-19 09:17:15.399: W/System.err(24886): <span style="white-space:pre">	</span>... 14 more
01-19 09:17:15.399: W/dalvikvm(24886): threadid=1: calling UncaughtExceptionHandler
01-19 09:17:15.406: E/AndroidRuntime(24886): FATAL EXCEPTION: main
01-19 09:17:15.406: E/AndroidRuntime(24886): java.lang.IllegalStateException: Could not execute method of the activity
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at android.view.View$1.onClick(View.java:3607)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at android.view.View.performClick(View.java:4227)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at android.view.View$PerformClick.run(View.java:17507)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at android.os.Handler.handleCallback(Handler.java:800)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at android.os.Handler.dispatchMessage(Handler.java:100)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at android.os.Looper.loop(Looper.java:194)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at android.app.ActivityThread.main(ActivityThread.java:5407)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at java.lang.reflect.Method.invokeNative(Native Method)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at java.lang.reflect.Method.invoke(Method.java:525)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at dalvik.system.NativeStart.main(Native Method)
01-19 09:17:15.406: E/AndroidRuntime(24886): Caused by: java.lang.reflect.InvocationTargetException
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at java.lang.reflect.Method.invokeNative(Native Method)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at java.lang.reflect.Method.invoke(Method.java:525)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at android.view.View$1.onClick(View.java:3602)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>... 11 more
01-19 09:17:15.406: E/AndroidRuntime(24886): Caused by: java.lang.NullPointerException
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at libcore.net.UriCodec.encode(UriCodec.java:132)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at java.net.URLEncoder.encode(URLEncoder.java:57)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>at com.alipay.sdk.pay.demo.PayDemoActivity.pay(PayDemoActivity.java:97)
01-19 09:17:15.406: E/AndroidRuntime(24886): <span style="white-space:pre">	</span>... 14 more
    在SignUtils类里将KeyFactory keyf = KeyFactory.getInstance(ALGORITHM);这句换成KeyFactory keyf = KeyFactory.getInstance(ALGORITHM,"BC");

 5、调用支付界面成功后,支付失败,检查是支付宝或支付宝绑定的银行卡是否有钱支付以及秘钥是否正确。


阅读更多
个人分类: 移动开发
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭