WithdrawTwoRepositories.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 WithdrawTwoRepositories
  12. {
  13. /** @var string 商户号 */
  14. private $mchid = '87';
  15. /** @var string 秘钥 */
  16. // private $mch_key='L7aW6VPTXSJeI29PsLaK7YQH6Mg4BVZl';
  17. private $mch_key = 'CCC1IWoNY0UETlHc10h2LAIxfsuFbbIT';
  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. 'merchantId' => $this->mchid,
  32. 'merchantUniqueOrderId' => $order,
  33. 'currency' => 'CNY',
  34. 'amount' => $money,
  35. 'bankCardNumber' => $accountno,
  36. 'bankName' => $bankname,
  37. 'bankRealName' => $accountname,
  38. 'notifyUrl' => getenv('API_HOST') . '/api/issue_two.html',
  39. ];
  40. $arr['sign'] = $this->sign($arr);
  41. $rst = Http::post('https://p6diha9u.vth1.xyz/interface/payments/CreateWithdrawOrder', $arr)->array();
  42. Log::channel('issue')->info('调下发', [
  43. '请求数据' => $arr,
  44. '回调数据' => $rst
  45. ]);
  46. if (Arr::get($rst, 'code') != 0) {
  47. throw new \Exception(Arr::get($rst, 'message', '请求失败'));
  48. }
  49. } catch (\Throwable $exception) {
  50. throw new \Exception($exception->getMessage());
  51. }
  52. return $rst;
  53. }
  54. /** 签名
  55. * @param $array
  56. * @return void
  57. */
  58. public function sign($array = [])
  59. {
  60. ksort($array); //ASCII码排序
  61. $md5str = "";
  62. $arr = [];
  63. foreach ($array as $key => $val) {
  64. $arr[] = $key . "=" . $val;
  65. // $md5str = $md5str . $key . "=" . $val . "&";
  66. }
  67. $sign = md5(implode('&', $arr) . $this->mch_key);
  68. return $sign;
  69. }
  70. }