Tlpay.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\common\payment;
  3. use Payment\Client\Refund;
  4. use Payment\Config;
  5. use Payment\Common\PayException;
  6. use support\Cache;
  7. class Tlpay
  8. {
  9. protected $config;
  10. public function __construct()
  11. {
  12. $this->config = config('payment.tl');
  13. }
  14. //当天交易请用撤销,非当天交易才用此退货接口
  15. public function refund($data)
  16. {
  17. $params = array();
  18. $params["cusid"] = AppConfig::CUSID;
  19. $params["appid"] = AppConfig::APPID;
  20. $params["version"] = AppConfig::APIVERSION;
  21. $params["trxamt"] = $data['trxamt'];
  22. $params["reqsn"] = $data['reqsn'];
  23. $params["oldtrxid"] = $data['oldtrxid'];//原来订单号
  24. $params["randomstr"] = $data['randomstr'];//
  25. $params["signtype"] = 'RSA';
  26. try {
  27. $params["sign"] = urlencode(AppUtil::Sign($params));//签名
  28. $paramsStr = AppUtil::ToUrlParams($params);
  29. $url = AppConfig::APIURL . "/refund";
  30. $rsp = http_post($url, $paramsStr);
  31. file_put_contents(runtime_path('logs/tlpay.log'), $rsp);
  32. return $rsp;
  33. } catch (\Exception $e) {
  34. throw new PayException("退款失败,原因:" . $e->getMessage());
  35. }
  36. }
  37. // public function refund($data)
  38. // {
  39. // if (!$data){
  40. // return json_fail('参数异常');
  41. // }
  42. //
  43. // try {
  44. // $ret = Refund::run(Config::TL_REFUND, $this->config, $data);
  45. //
  46. // file_put_contents(runtime_path('logs/tlpay.log'),json_encode($ret, JSON_UNESCAPED_UNICODE));
  47. // return $ret;
  48. // } catch (PayException $e) {
  49. // dump($e->getMessage());
  50. // throw new PayException("发起退款失败");
  51. // }
  52. //
  53. // }
  54. }