Coder Social home page Coder Social logo

hqdmyjsw / android-pay Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mayubao/android-pay

0.0 1.0 0.0 529 KB

支持微信和支付宝两种主流支付的集成库, 两行代码实现微信支付, 三行代码实现支付宝支付

Java 100.00%

android-pay's Introduction

Android-Pay

支持微信和支付宝两种主流支付的集成库, 两行代码实现微信支付, 三行代码实现支付宝支付

引入

gradle

对应的项目中的build.gradle文件添加依赖:

dependencies {
    //添加支付库
    compile 'io.github.mayubao:pay_library:1.0.0'
}

maven

<dependency>
  <groupId>io.github.mayubao</groupId>
  <artifactId>pay_library</artifactId>
  <version>1.0.0</version>
  <type>pom</type>
</dependency>

使用

微信支付使用

        //1.创建微信支付请求
        WechatPayReq wechatPayReq = new WechatPayReq.Builder()
                .with(this) //activity实例
                .setAppId(appid) //微信支付AppID
                .setPartnerId(partnerid)//微信支付商户号
                .setPrepayId(prepayid)//预支付码
//								.setPackageValue(wechatPayReq.get)//"Sign=WXPay"
                .setNonceStr(noncestr)
                .setTimeStamp(timestamp)//时间戳
                .setSign(sign)//签名
                .create();
        //2.发送微信支付请求
        PayAPI.getInstance().sendPayRequest(wechatPayReq);
        
        
        //关于微信支付的回调
        //wechatPayReq.setOnWechatPayListener(new OnWechatPayListener);
        

注意:这里没有金额设置,金额的信息已经包含在预支付码prepayid了。

支付宝支付使用

        //1.创建支付宝支付配置
        AliPayAPI.Config config = new AliPayAPI.Config.Builder()
                .setRsaPrivate(rsa_private) //设置私钥 (商户私钥,pkcs8格式)
                .setRsaPublic(rsa_public)//设置公钥(// 支付宝公钥)
                .setPartner(partner) //设置商户
                .setSeller(seller) //设置商户收款账号
                .create();

        //2.创建支付宝支付请求
        AliPayReq aliPayReq = new AliPayReq.Builder()
                .with(activity)//Activity实例
                .apply(config)//支付宝支付通用配置
                .setOutTradeNo(outTradeNo)//设置唯一订单号
                .setPrice(price)//设置订单价格
                .setSubject(orderSubject)//设置订单标题
                .setBody(orderBody)//设置订单内容 订单详情
                .setCallbackUrl(callbackUrl)//设置回调地址
                .create()//
                .setOnAliPayListener(null);//

        //3.发送支付宝支付请求
        PayAPI.getInstance().sendPayRequest(aliPayReq);
        
        //关于支付宝支付的回调
        //aliPayReq.setOnAliPayListener(new OnAliPayListener);

混淆

#pay_library
-dontwarn io.github.mayubao.pay_library.**
-keep class io.github.mayubao.pay_library.** {*;}

#wechat pay
-dontwarn com.tencent.**
-keep class com.tencent.** {*;}


#alipay
-dontwarn com.alipay.**
-keep class com.alipay.** {*;}

-dontwarn  com.ta.utdid2.**
-keep class com.ta.utdid2.** {*;}

-dontwarn  com.ut.device.**
-keep class com.ut.device.** {*;}

-dontwarn  org.json.alipay.**
-keep class corg.json.alipay.** {*;}

文档

微信支付官方文档 支付流程

https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_5

支付宝支付官方文档 支付流程

https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.sdGXaH&treeId=204&articleId=105296&docType=1

注意

微信支付

  • 微信支付必须要在正式签名正确包名的应用中才能成功调起。(**重点)

    即商户在微信开放平台申请开发应用后对应包名和对应签名的应用才能成功调起。 详情请参考微信支付的开发流程文档。

    https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_5

  • 微信支付API没有在客户端显示的设置回调,回调是在Server端设置的。(与支付宝支付的区别,支付宝的回调是在客户端设置的)

支付宝支付

打赏

如果你觉得此项目对你有用,能否赏我一杯咖啡呢?

微信支付

支付宝支付

支付宝支付

Copyright 2017 mayubao

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

android-pay's People

Contributors

mayubao avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.