api-upload-file.php 1007 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * 通用接口调用 -> 附件上传
  4. */
  5. require_once '../../vendor/autoload.php';
  6. $config = new \Lakala\OpenAPISDK\V2\V2Configuration();
  7. $api = new \Lakala\OpenAPISDK\V2\Api\V2LakalaApi($config);
  8. try {
  9. $request = new \Lakala\OpenAPISDK\V2\Model\V2ModelRequest();
  10. $data = file_get_contents('FR_ID_CARD_FRONT.jpg');
  11. $attContext = base64_encode($data);
  12. // 请求字段 - 法人身份证正面
  13. $request->setReqData([
  14. 'attContext' => $attContext,
  15. 'attType' => 'FR_ID_CARD_FRONT',
  16. 'attExtName' => 'jpg',
  17. 'orderNo' => '20231012113426kjEnsUsE',
  18. 'orgCode' => '1',
  19. 'version' => '1.0',
  20. ]);
  21. $response = $api->tradeApi('/api/v2/mms/openApi/uploadFile', $request);
  22. print_r($response);
  23. echo $response->getRetCode();
  24. # 响应头信息
  25. print_r($response->getHeaders());
  26. # 响应原文
  27. echo $response->getOriginalText();
  28. } catch (\Lakala\OpenAPISDK\V2\V2ApiException $e) {
  29. echo $e->getMessage();
  30. }