WithdrawRepositories.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace plugin\admin\app\repositories;
  3. use app\api\repositories\MoneyLogRepositories;
  4. use Illuminate\Support\Arr;
  5. use plugin\admin\app\model\BankCard;
  6. use plugin\admin\app\model\System;
  7. use plugin\admin\app\model\User;
  8. use plugin\admin\app\model\Withdraw;
  9. use support\Log;
  10. use yzh52521\EasyHttp\Http;
  11. class WithdrawRepositories
  12. {
  13. /** @var string 商户号 */
  14. private $mchid = '500084';
  15. /** @var string 秘钥 */
  16. // private $mch_key='L7aW6VPTXSJeI29PsLaK7YQH6Mg4BVZl';
  17. private $mch_key = 'TC1IKPE1Sx4Id0n1B0m10Zr4Bj287P46';
  18. /** 申请提现
  19. * @param $order 订单号
  20. * @param $money 下发金额
  21. * @param $bankname 归属银行
  22. * @param $accountname 开户人
  23. * @param $accountno 卡号
  24. * @return array|mixed
  25. * @throws \Exception
  26. */
  27. public function batchdelivery($order, $money, $bankname, $accountname, $accountno)
  28. {
  29. try {
  30. $arr = [
  31. 'amount' => $money,
  32. 'outOrderNum' => $order,
  33. 'mchNum' => $this->mchid,
  34. 'timestamp' => date('YmdHis'),
  35. 'account' => $accountno,
  36. 'accountName' => $accountname,
  37. 'bankName' => $bankname,
  38. 'notifyUrl' => getenv('API_HOST') . '/api/issue.html',
  39. ];
  40. $arr['sign'] = $this->sign($arr);
  41. $rst = Http::post('http://sepaydf.tr16688.com/dfApi/order', $arr)->array();
  42. // $rst = [];
  43. Log::channel('issue')->info('调下发', [
  44. '请求数据' => $arr,
  45. '回调数据' => $rst
  46. ]);
  47. if (Arr::get($rst, 'code') == 0) {
  48. throw new \Exception(Arr::get($rst, 'message', '请求失败'));
  49. }
  50. } catch (\Throwable $exception) {
  51. throw new \Exception($exception->getMessage());
  52. }
  53. return $rst;
  54. }
  55. /** 签名
  56. * @param $array
  57. * @return void
  58. */
  59. public function sign($array = [])
  60. {
  61. ksort($array); //ASCII码排序
  62. $md5str = "";
  63. $arr = [];
  64. foreach ($array as $key => $val) {
  65. $arr[] = $key . "=" . $val;
  66. // $md5str = $md5str . $key . "=" . $val . "&";
  67. }
  68. $sign = md5(implode('&', $arr) . $this->mch_key);
  69. return $sign;
  70. }
  71. }