Skip to content

wcj343169893/omnipay-alipay

Repository files navigation

Omnipay: Alipay

travis Latest Version on Packagist Total Downloads Code Coverage Software License Donate Donate

Alipay driver for the Omnipay PHP payment processing library

Omnipay is a framework agnostic, multi-gateway payment processing library for PHP. This package implements Alipay support for Omnipay.

Cross-border Alipay payment please use lokielse/omnipay-global-alipay

Legacy Version please use "lokielse/omnipay-alipay": "dev-legacy"

Installation

Omnipay is installed via Composer. To install, simply add it to your composer.json file:

"lokielse/omnipay-alipay": "^2.0",

And run composer to update your dependencies:

$ composer update -vvv

Basic Usage

The following gateways are provided by this package:

Gateway Description 说明   Links
Alipay_AopPage Alipay Page Gateway 电脑网站支付 - new Usage Doc
Alipay_AopApp Alipay APP Gateway APP支付 - new Usage Doc
Alipay_AopF2F Alipay Face To Face Gateway 当面付 - new Usage Doc
Alipay_AopWap Alipay WAP Gateway 手机网站支付 - new Usage Doc
Alipay_AopJs Alipay Js Gateway JSAPI - new Usage Doc
Alipay_LegacyApp Alipay Legacy APP Gateway APP支付 Usage Doc
Alipay_LegacyExpress Alipay Legacy Express Gateway 即时到账 Usage Doc
Alipay_LegacyWap Alipay Legacy WAP Gateway 手机网站支付 Usage Doc
Alipay_Oauth Alipay Oauth 支付宝自动授权登陆

Usage

支付宝自动登录

/**
 *
 * @var \Omnipay\Alipay\OauthGateway $gateway
 */
$gateway = Omnipay::create("Alipay_Oauth");
$gateway->setSignType('RSA2'); // RSA/RSA2/MD5
$gateway->setAppId($this->getConfig("appId"));
$gateway->setPrivateKey($this->getConfig("privateKey"));
$gateway->setAlipayPublicKey($this->getConfig("alipayPublicKey"));

/**
 *
 * @var \Omnipay\Alipay\Requests\SystemOauthTokenRequest $request
 */
$request = $gateway->purchase();
if (! empty($refreshToken)) {
    $request->setRefreshToken($refreshToken);
} else {
    $request->setCode($code);
}
$response = $request->send();
if($response->isSuccessful()){
    return $response->getData();
}
return false;

Purchase (购买)

/**
 * @var AopAppGateway $gateway
 */
$gateway = Omnipay::create('Alipay_AopPage');
$gateway->setSignType('RSA2'); // RSA/RSA2/MD5
$gateway->setAppId('the_app_id');
$gateway->setPrivateKey('the_app_private_key');
$gateway->setAlipayPublicKey('the_alipay_public_key');
$gateway->setReturnUrl('https://www.example.com/return');
$gateway->setNotifyUrl('https://www.example.com/notify');

/**
 * @var AopTradePagePayResponse $response
 */
$response = $gateway->purchase()->setBizContent([
    'subject'      => 'test',
    'out_trade_no' => date('YmdHis') . mt_rand(1000, 9999),
    'total_amount' => '0.01',
    'product_code' => 'FAST_INSTANT_TRADE_PAY',
])->send();

$url = $response->getRedirectUrl();

支付宝sdk授权登陆签名

$gateway = Omnipay::create("Alipay_Sdk");
$gateway->setSignType('RSA2');
$gateway->setAppId('the_app_id');
$gateway->setPid("parter_id");
$gateway->setAppId('the_app_id');
$gateway->setPrivateKey('the_app_private_key');
$gateway->setAlipayPublicKey('the_alipay_public_key');
$request = $gateway->purchase();
$data= $request->getData();

返回 { "apiname": "com.alipay.account.auth", "app_id": "201510000934009", "app_name": "mc", "auth_type": "AUTHACCOUNT", "biz_type": "openservice", "method": "alipay.open.auth.sdk.code.get", "pid": "208831001128084", "product_id": "APP_FAST_LOGIN", "scope": "kuaijie", "sign_type": "RSA2", "target_id": "2018091018001867226", "sign": "BtAZTli9Lv7rRJxD14139v/5g0nCH1vIwn/1SsNQpL1FQrgLkizUeN/pwa5Dnmz5i0jV0Rbj3tKR4z1uxFojthIzum0gQ9TmaxZwNsOFfwg1JFoqAy41cOEHp9nnhDeDjr/SZa00BIPtjgN/pwcQhS6za/8xfiG8EAcjptjNsQTgKm2OcwOdcp7xjUBAqk49feJ+PRVxmQ1+XVjyRs+QkI4CFLh1aDl59vYZkHJKP9Y7NnSn18aX66PtQ5+B9v2L34pV+E9uly3f3tTHl/2SSI9NRFgCQxukHWwTGa7LmDjo16/jaUymGiMVDHO/Hz1zH6K4KAbs+qTLWLCaHEVBTw==" }

For general usage instructions, please see the main Omnipay repository.

Related

Support

If you are having general issues with Omnipay, we suggest posting on Stack Overflow. Be sure to add the omnipay tag so it can be easily found.

If you want to keep up to date with release anouncements, discuss ideas for the project, or ask more detailed questions, there is also a mailing list which you can subscribe to.

If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request.