glhcp/server/vendor/alipaysdk/easysdk/php/README.md

230 lines
13 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

[![Latest Stable Version](https://poser.pugx.org/alipaysdk/easysdk/v/stable)](https://packagist.org/packages/alipaysdk/easysdk)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Falipay%2Falipay-easysdk.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Falipay%2Falipay-easysdk?ref=badge_shield)
使 Alipay **Easy** SDK for PHP
Alipay Esay SDK for PHP访SDKHTTP
Alipay Easy SDK for PHP 使
##
[Alipay SDK](https://openhome.alipay.com/doc/sdkDownload.resource?sdkType=PHP)通用而全面的设计理念Alipay Easy SDK对开放能力的API进行了更加贴近高频场景的精心设计与裁剪简化了服务端调用方式让调用API像使用语言内置的函数一样简便。
Alipay Easy SDK[](https://opendocs.alipay.com/mini/00am3f)相对应的代码组织结构让开发者可以快速找到不同能力对应的API。
Alipay Easy SDK****
##
1. Alipay Easy SDK for PHP `PHP 7.0`
2. 使 Alipay Easy SDK for PHP [-](https://openhome.alipay.com/platform/developerIndex.htm)完成开发者接入的一些准备工作,包括创建应用、为应用添加功能包、设置应用的接口加签方式等。
3. 使SDK
*
`AppId`````````
*
`AppId`````
##
### [Composer](https://packagist.org/packages/alipaysdk/easysdk/)在线安装依赖(推荐)
`composer require alipaysdk/easysdk:^2.2`
###
1. [Composer](https://getcomposer.org/)工具。
2. `README.md``composer install`SDK
3. `vendor`
## 使
使Alipay Easy SDK for PHPAPI3
1.
2. API
3.
```php
<?php
require 'vendor/autoload.php';
use Alipay\EasySDK\Kernel\Factory;
use Alipay\EasySDK\Kernel\Util\ResponseChecker;
use Alipay\EasySDK\Kernel\Config;
//1. 设置参数(全局只需设置一次)
Factory::setOptions(getOptions());
try {
//2. 发起API调用以支付能力下的统一收单交易创建接口为例
$result = Factory::payment()->common()->create("iPhone6 16G", "20200326235526001", "88.88", "2088002656718920");
$responseChecker = new ResponseChecker();
//3. 处理响应或异常
if ($responseChecker->success($result)) {
echo "调用成功". PHP_EOL;
} else {
echo "调用失败,原因:". $result->msg."".$result->subMsg.PHP_EOL;
}
} catch (Exception $e) {
echo "调用失败,". $e->getMessage(). PHP_EOL;;
}
function getOptions()
{
$options = new Config();
$options->protocol = 'https';
$options->gatewayHost = 'openapi.alipay.com';
$options->signType = 'RSA2';
$options->appId = '<-- AppId2019022663440152 -->';
// 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
$options->merchantPrivateKey = '<-- MIIEvQIBADANB ... ... -->';
$options->alipayCertPath = '<-- /foo/alipayCertPublicKey_RSA2.crt -->';
$options->alipayRootCertPath = '<-- /foo/alipayRootCert.crt" -->';
$options->merchantCertPath = '<-- 请填写您的应用公钥证书文件路径,例如:/foo/appCertPublicKey_2019051064521003.crt -->';
//注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
// $options->alipayPublicKey = '<-- 请填写您的支付宝公钥例如MIIBIjANBg... -->';
//可设置异步通知接收服务地址(可选)
$options->notifyUrl = "<-- https://www.test.com/callback -->";
//可设置AES密钥调用AES加解密相关接口时需要可选
$options->encryptKey = "<-- 请填写您的AES密钥例如aa4BtZ4tspm2wnXLb1ThQA== -->";
return $options;
}
```
###
#### ISV
```php
Factory::payment()->faceToFace()
// 调用agent扩展方法设置app_auth_token完成ISV代调用
->agent("ca34ea491e7146cc87d25fca24c4cD11")
->preCreate("Apple iPhone11 128G", "2234567890", "5799.00");
```
####
```php
Factory::payment()->faceToFace()
// 调用asyncNotify扩展方法可以为每此API调用设置独立的异步通知地址
// 此处设置的异步通知地址的优先级高于全局Config中配置的异步通知地址
->asyncNotify("https://www.test.com/callback")
->preCreate("Apple iPhone11 128G", "2234567890", "5799.00");
```
####
```php
$goodDetail = array(
"goods_id" => "apple-01",
"goods_name" => "iPhone6 16G",
"quantity" => 1,
"price" => "5799"
);
$goodsDetail[0] = $goodDetail;
Factory::payment()->faceToFace()
// 调用optional扩展方法完成可选业务参数biz_content下的可选字段的设置
->optional("seller_id", "2088102146225135")
->optional("discountable_amount", "8.88")
->optional("goods_detail", $goodsDetail)
->preCreate("Apple iPhone11 128G", "2234567890", "5799.00");
$optionalArgs = array(
"timeout_express" => "10m",
"body" => "Iphone6 16G"
);
Factory::payment()->faceToFace()
// 也可以调用batchOptional扩展方法批量设置可选业务参数biz_content下的可选字段
->batchOptional($optionalArgs)
->preCreate("Apple iPhone11 128G", "2234567890", "5799.00");
```
####
```php
// 多种扩展方式可灵活组装(对扩展方法的调用顺序没有要求)
Factory::payment()->faceToFace()
->agent("ca34ea491e7146cc87d25fca24c4cD11")
->asyncNotify("https://www.test.com/callback")
->optional("seller_id", "2088102146225135")
->preCreate("Apple iPhone11 128G", "2234567890", "5799.00");
```
## API
Alipay Easy SDKAPI
> Factory::()->()->( ... )
使[](https://opendocs.alipay.com/mini/00am3f)中`营销能力`下的`模板消息`场景中的`小程序发送模板消息`,只需按如下形式编写调用代码即可(不同编程语言的连接符号可能不同)。
`Factory::marketing()->templateMessage()->send( ... )`
OpenAPIOpenAPIOpenAPI使
Alipay Easy SDKAPI
## API
| | | | OpenAPI |
|-----------|-----------------|------------------------|-----------------------------------------------------------|
| Base | OAuth | getToken | alipay\.system\.oauth\.token |
| Base | OAuth | refreshToken | alipay\.system\.oauth\.token |
| Base | Qrcode | create | alipay\.open\.app\.qrcode\.create |
| Base | Image | upload | alipay\.offline\.material\.image\.upload |
| Base | Video | upload | alipay\.offline\.material\.image\.upload |
| Member | Identification | init | alipay\.user\.certify\.open\.initialize |
| Member | Identification | certify | alipay\.user\.certify\.open\.certify |
| Member | Identification | query | alipay\.user\.certify\.open\.query |
| Payment | Common | create | alipay\.trade\.create |
| Payment | Common | query | alipay\.trade\.query |
| Payment | Common | refund | alipay\.trade\.refund |
| Payment | Common | close | alipay\.trade\.close |
| Payment | Common | cancel | alipay\.trade\.cancel |
| Payment | Common | queryRefund | alipay\.trade\.fastpay\.refund\.query |
| Payment | Common | downloadBill | alipay\.data\.dataservice\.bill\.downloadurl\.query |
| Payment | Common | verifyNotify | - |
| Payment | Huabei | create | alipay\.trade\.create |
| Payment | FaceToFace | pay | alipay\.trade\.pay |
| Payment | FaceToFace | precreate | alipay\.trade\.precreate |
| Payment | App | pay | alipay\.trade\.app\.pay |
| Payment | Page | pay | alipay\.trade\.page\.pay |
| Payment | Wap | pay | alipay\.trade\.wap\.pay |
| Security | TextRisk | detect | alipay\.security\.risk\.content\.detect |
| Marketing | Pass | createTemplate | alipay\.pass\.template\.add |
| Marketing | Pass | updateTemplate | alipay\.pass\.template\.update |
| Marketing | Pass | addInstance | alipay\.pass\.instance\.add |
| Marketing | Pass | updateInstance | alipay\.pass\.instance\.update |
| Marketing | TemplateMessage | send | alipay\.open\.app\.mini\.templatemessage\.send |
| Marketing | OpenLife | createImageTextContent | alipay\.open\.public\.message\.content\.create |
| Marketing | OpenLife | modifyImageTextContent | alipay\.open\.public\.message\.content\.modify |
| Marketing | OpenLife | sendText | alipay\.open\.public\.message\.total\.send |
| Marketing | OpenLife | sendImageText | alipay\.open\.public\.message\.total\.send |
| Marketing | OpenLife | sendSingleMessage | alipay\.open\.public\.message\.single\.send |
| Marketing | OpenLife | recallMessage | alipay\.open\.public\.life\.msg\.recall |
| Marketing | OpenLife | setIndustry | alipay\.open\.public\.template\.message\.industry\.modify |
| Marketing | OpenLife | getIndustry | alipay\.open\.public\.setting\.category\.query |
| Util | AES | decrypt | - |
| Util | AES | encrypt | - |
| Util | Generic | execute | - |
| Util | Generic | sdkExecute | - |
| Util | Generic | fileExecute | - |
> API
##
[API Doc](./../APIDoc.md)
[Alipay Easy SDK](./../README.md)