功能很简单,主要通过隐式意图完成
代码如下:
[java] 查看纯文本
- package com.example.gk.testalipay;
- import android.content.Context;
- 导入 android.content.Intent;
- 导入 android.net.Uri;
- 导入 android.support.v7.app.AppCompatActivity;
- 导入 android.os.Bundle;
- 导入 android.view.View;
- 导入 android.widget.Button;
- 导入 android.widget.Toast;
- import java.net.URLEncoder;
- / **
- *测试不集成sdk,直接对商户个人二维码个人收款码进行转账
- *个人二维码可以截图下来。通过扫码工具获得里面的字符串
- * /
- public class MainActivity extends AppCompatActivity implements View.OnClickListener {
- public static final String ALIPAY_SHOP = “https://qr.alipay.com/stx05107r5oaa4fyofbkh24” ; //商户
- public static final String ALIPAY_PERSON = “HTTPS://QR.ALIPAY.COM/FKX06148QMZIJDXGPKXXE7” ; //个人(支付宝里面我的二维码)
- public static final String ALIPAY_PERSON_2_PAY = “HTTPS://QR.ALIPAY.COM/FKX01415BIHINQT6TRU53F” ; //个人(支付宝里面我的二维码,然后提示让用的收款码)
- 私人 按钮btn_to_shop;
- 私人 按钮btn_to_person;
- 私人 按钮btn_to_person_pay;
- @覆盖
- protected void onCreate(Bundle savedInstanceState){
- 超级.onCreate(savedInstanceState);
- 的setContentView(R.layout.activity_main);
- initViews();
- initEvent();
- }
- private void initEvent(){
- btn_to_shop.setOnClickListener(this );
- btn_to_person.setOnClickListener(this );
- btn_to_person_pay.setOnClickListener(this );
- }
- private void initViews(){
- btn_to_shop =(Button)findViewById(R.id.btn_to_shop);
- btn_to_person =(Button)findViewById(R.id.btn_to_person);
- btn_to_person_pay =(Button)findViewById(R.id.btn_to_person_pay);
- }
- @覆盖
- public void onClick(View v){
- switch (v.getId()){
- 案例 R.id.btn_to_shop:
- openAliPay2Pay(ALIPAY_SHOP);
- 打破;
- 案例 R.id.btn_to_person:
- openAliPay2Pay(ALIPAY_PERSON);
- 打破;
- case R.id.btn_to_person_pay:
- openAliPay2Pay(ALIPAY_PERSON_2_PAY);
- 打破;
- 默认值:
- 打破;
- }
- }
- / **
- *支付
- *
- * @param qrCode
- * /
- private void openAliPay2Pay(String qrCode){
- if (openAlipayPayPage(this ,qrCode)){
- Toast.makeText(this , “跳转成功” ,Toast.LENGTH_SHORT).show();
- } else {
- Toast.makeText(this , “跳转失败” ,Toast.LENGTH_SHORT).show();
- }
- }
- public static boolean openAlipayPayPage(Context context,String qrcode){
- 尝试 {
- qrcode = URLEncoder.encode(qrcode, “utf-8” );
- } catch (Exception e){
- }
- 尝试 {
- final String alipayqr = “alipayqr:// platformapi / startapp?saId = 10000007&clientVersion = 3.7.0.0718&qrcode =” + qrcode;
- openUri(context,alipayqr + “%3F_s%3Dweb-other&_t =” + System.currentTimeMillis());
- 返回真;
- } catch (Exception e){
- e.printStackTrace();
- }
- 返回假;
- }
- / **
- *发送一个意图
- *
- * @param上下文
- * @param s
- * /
- private static void openUri(Context context,String s){
- Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(s));
- context.startActivity(意向);
- }
- }
不过没有集成sdk是没有办法知道用户支付状态的,除非让用户复制交易订单号然后用一个支付宝的接口进行查询
这样的功能适合个人开发的小应用。不适合商业项目