当前位置:首页 > 安卓源码 > 技术博客 >

Android不集成支付宝sdk实现收款功能通过Intent调起支付宝支付

时间:2017-10-13 17:32 来源:互联网 作者:源码搜藏 浏览: 收藏 挑错 推荐 打印

功能很简单,主要通过隐式意图完成 代码如下: [java] 查看纯 文本 package com.example.gk.testalipay; import android.content.Context; 导入 android.content.Intent; 导入 android.net.Uri; 导入 android.support.v7.app.AppCompatActivity; 导入 androi

功能很简单,主要通过隐式意图完成

代码如下:

 

[java] 查看纯文本 
 
  1. package  com.example.gk.testalipay;  
  2.   
  3. import  android.content.Context;  
  4. 导入 android.content.Intent;  
  5. 导入 android.net.Uri;  
  6. 导入 android.support.v7.app.AppCompatActivity;  
  7. 导入 android.os.Bundle;  
  8. 导入 android.view.View;  
  9. 导入 android.widget.Button;  
  10. 导入 android.widget.Toast;  
  11.   
  12. import  java.net.URLEncoder;  
  13.   
  14. / ** 
  15.  *测试不集成sdk,直接对商户个人二维码个人收款码进行转账 
  16.  *个人二维码可以截图下来。通过扫码工具获得里面的字符串 
  17.  * /  
  18. public class  MainActivity  extends  AppCompatActivity  implements  View.OnClickListener {   
  19.     public static final  String ALIPAY_SHOP =  “https://qr.alipay.com/stx05107r5oaa4fyofbkh24” ; //商户    
  20.     public static final  String ALIPAY_PERSON =  “HTTPS://QR.ALIPAY.COM/FKX06148QMZIJDXGPKXXE7” ; //个人(支付宝里面我的二维码)    
  21.     public static final  String ALIPAY_PERSON_2_PAY =  “HTTPS://QR.ALIPAY.COM/FKX01415BIHINQT6TRU53F” ; //个人(支付宝里面我的二维码,然后提示让用的收款码)    
  22.     私人 按钮btn_to_shop;  
  23.     私人 按钮btn_to_person;  
  24.     私人 按钮btn_to_person_pay;  
  25.   
  26.     @覆盖  
  27.     protected void  onCreate(Bundle savedInstanceState){   
  28.         超级.onCreate(savedInstanceState);  
  29.         的setContentView(R.layout.activity_main);  
  30.         initViews();  
  31.         initEvent();  
  32.     }  
  33.   
  34.     private void  initEvent(){   
  35.         btn_to_shop.setOnClickListener(this );  
  36.         btn_to_person.setOnClickListener(this );  
  37.         btn_to_person_pay.setOnClickListener(this );  
  38.     }  
  39.   
  40.     private void  initViews(){   
  41.         btn_to_shop =(Button)findViewById(R.id.btn_to_shop);  
  42.         btn_to_person =(Button)findViewById(R.id.btn_to_person);  
  43.         btn_to_person_pay =(Button)findViewById(R.id.btn_to_person_pay);  
  44.     }  
  45.   
  46.     @覆盖  
  47.     public void  onClick(View v){   
  48.         switch  (v.getId()){  
  49.             案例 R.id.btn_to_shop:  
  50.                 openAliPay2Pay(ALIPAY_SHOP);  
  51.                 打破;  
  52.             案例 R.id.btn_to_person:  
  53.                 openAliPay2Pay(ALIPAY_PERSON);  
  54.                 打破;  
  55.             case  R.id.btn_to_person_pay:  
  56.                 openAliPay2Pay(ALIPAY_PERSON_2_PAY);  
  57.                 打破;  
  58.             默认值:  
  59.                 打破;  
  60.         }  
  61.     }  
  62.   
  63.     / ** 
  64.      *支付 
  65.      * 
  66.      * @param qrCode 
  67.      * /  
  68.     private void  openAliPay2Pay(String qrCode){   
  69.         if  (openAlipayPayPage(this ,qrCode)){  
  70.             Toast.makeText(this ,  “跳转成功” ,Toast.LENGTH_SHORT).show();  
  71.         }  else  {  
  72.             Toast.makeText(this ,  “跳转失败” ,Toast.LENGTH_SHORT).show();  
  73.         }  
  74.     }  
  75.   
  76.     public static boolean  openAlipayPayPage(Context context,String qrcode){    
  77.         尝试 {  
  78.             qrcode = URLEncoder.encode(qrcode,  “utf-8” );  
  79.         }  catch  (Exception e){  
  80.         }  
  81.         尝试 {  
  82.             final  String alipayqr =  “alipayqr:// platformapi / startapp?saId = 10000007&clientVersion = 3.7.0.0718&qrcode =”  + qrcode;  
  83.             openUri(con​​text,alipayqr +  “%3F_s%3Dweb-other&_t =”  + System.currentTimeMillis());  
  84.             返回;   
  85.         }  catch  (Exception e){  
  86.             e.printStackTrace();  
  87.         }  
  88.         返回;   
  89.     }  
  90.   
  91.     / ** 
  92.      *发送一个意图 
  93.      * 
  94.      * @param上下文 
  95.      * @param s 
  96.      * /  
  97.     private static void  openUri(Context context,String s){    
  98.         Intent intent =  new  Intent(Intent.ACTION_VIEW,Uri.parse(s));  
  99.         context.startActivity(意向);  
  100.     }  
  101. }  

不过没有集成sdk是没有办法知道用户支付状态的,除非让用户复制交易订单号然后用一个支付宝的接口进行查询

 

这样的功能适合个人开发的小应用。不适合商业项目

Android不集成支付宝sdk实现收款功能通过Intent调起支付宝支付 转载https://www.codesocang.com/appboke/36679.html

技术博客阅读排行

最新文章