MMSService.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. declare(strict_types=1);
  3. namespace SixShop\Lakala\Service;
  4. use SixShop\Lakala\Config;
  5. use SixShop\Lakala\Enum\UploadFileTypeEnum;
  6. use SixShop\Lakala\OpenAPISDK\V2\Api\V2LakalaApi;
  7. use SixShop\Lakala\OpenAPISDK\V2\Model\V2ModelRequest;
  8. use function SixShop\Core\throw_logic_exception;
  9. class MMSService
  10. {
  11. private V2LakalaApi $v2LakalaApi;
  12. public function __construct(private Config $config)
  13. {
  14. $this->v2LakalaApi = new V2LakalaApi($config->getV2Config());
  15. }
  16. /**
  17. * 卡BIN查询
  18. *
  19. * @param string $orderNo 订单编号(便于后续跟踪排查问题及核对报文) 14位年月日时(24小时制)分秒+8位的随机数(不重复)如:2021020112000012345678
  20. * @param string $cardNo 银行卡号
  21. * @param string $orgCode 机构代码
  22. * @param string $version 接口版本号 默认1.0
  23. * @link https://o.lakala.com/#/home/document/detail?id=179
  24. */
  25. public function cardBin(string $orderNo, string $cardNo,string $orgCode = '1', string $version = '1.0'):object
  26. {
  27. $request = new V2ModelRequest();
  28. $request->setReqData([
  29. 'version' => $version,
  30. 'orderNo' => $orderNo,
  31. 'orgCode' => $orgCode,
  32. 'cardNo' => $cardNo,
  33. ]);
  34. $response = $this->v2LakalaApi->tradeApi('/api/v2/mms/openApi/cardBin', $request);
  35. if ($response->getRetCode() == '000000') {
  36. $result = $response->getRespData();
  37. if ($result->bankCode && $result->clearingBankCode) {
  38. return $result;
  39. } else {
  40. throw_logic_exception('未获取到开户行信息');
  41. }
  42. } else {
  43. throw_logic_exception(
  44. msg:$response->getRetMsg(),
  45. code: (int)$response->getRetCode(),
  46. data: $response->getRespData(),
  47. );
  48. }
  49. }
  50. /**
  51. * 附件上传
  52. *
  53. * @param string $orderNo
  54. * @param UploadFileTypeEnum $attType
  55. * @param string $attExtName
  56. * @param string $fileContent
  57. * @param string $orgCode
  58. * @param string $version
  59. *
  60. * @link https://o.lakala.com/#/home/document/detail?id=90
  61. */
  62. public function uploadFile(string $orderNo, UploadFileTypeEnum $attType, string $attExtName, string $fileContent, string $orgCode = '1', string $version = '1.0')
  63. {
  64. $request = new V2ModelRequest();
  65. $attContext = base64_encode($fileContent);
  66. $request->setReqData([
  67. 'attContext' => $attContext,
  68. 'attType' => $attType->value,
  69. 'attExtName' => $attExtName,
  70. 'orderNo' => $orderNo,
  71. 'orgCode' => $orgCode,
  72. 'version' => $version,
  73. ]);
  74. $response = $this->v2LakalaApi->tradeApi('/api/v2/mms/openApi/uploadFile', $request);
  75. if ($response->getRetCode() == '000000') {
  76. return $response->getRespData();
  77. } else {
  78. throw_logic_exception(
  79. msg:$response->getRetMsg(),
  80. code: (int)$response->getRetCode(),
  81. data: $response->getRespData(),
  82. );
  83. }
  84. }
  85. }