ihome520 / lop-opensdk-php
There is no license information available for the latest version (v1.2) of this package.
v1.2
2024-11-19 10:35 UTC
Requires
- php: >=5.6
- ext-json: *
- guzzlehttp/guzzle: ^7.2
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is auto-updated.
Last update: 2024-12-19 10:50:49 UTC
README
2024-06-20 fork修改版本,支持Laravel 9.3.33
本仓库fork来源于:https://github.com/gangaoh/lop-opensdk-php 旧版本的Laravel请使用原来的版本
安装
composer require ihome520/lop-opensdk-php -vvv
请求示例
<?php require_once __DIR__ . "/vendor/autoload.php"; use Lop\LopOpensdkPhp\Filters\ErrorResponseFilter; use Lop\LopOpensdkPhp\Filters\IsvFilter; use Lop\LopOpensdkPhp\Filters\LoggerFilter; use Lop\LopOpensdkPhp\Options; use Lop\LopOpensdkPhp\Support\DefaultClient; use Lop\LopOpensdkPhp\Support\GenericRequest; // 生产环境: https://api.jdl.com $client = new DefaultClient("{BASE_URI}"); $isvFilter = new IsvFilter("{APP_KEY}", "{APP_SECRET}", "{ACCESS_TOKEN}"); // STDOUT是PHP内置常量,表示输出到标准输出(控制台) $loggerFilter = new LoggerFilter(STDOUT); $errorResponseFilter = new ErrorResponseFilter(); $request = new GenericRequest(); $request->setDomain("{DOMAIN}");//对接方案的编码,应用订购对接方案后可在订阅记录查看 $request->setPath("{PATH}");//api的path,可在API文档查看 $request->setMethod("POST");//只支持POST // 序列化后的JSON字符串 $request->setBody("{BODY}"); // 为请求添加ISV模式过滤器,自动根据算法计算开放平台鉴权及签名信息 $request->addFilter($isvFilter); // 为请求添加日志过滤器,日志将会输出到STDOUT,建议仅在测试时使用 $request->addFilter($loggerFilter); // 为请求添加错误响应解析过滤器,如果不添加需要手动解析错误响应 $request->addFilter($errorResponseFilter); $options = new Options(); $options->setAlgorithm(Options::MD5_SALT); //$options->setAlgorithm(Options::HMAC_MD5); //$options->setAlgorithm(Options::HMAC_SHA1); //$options->setAlgorithm(Options::HMAC_SHA256); //$options->setAlgorithm(Options::HMAC_SHA512); $response = $client->execute($request, $options); echo $response->getBody();