MobileRechargeService.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace crmeb\services;
  3. use app\models\user\UserMobileRecharge;
  4. class MobileRechargeService
  5. {
  6. private static $domain = 'https://api.nyyun.cn';
  7. private static $app_id = 'nyeu184mkg';
  8. private static $app_secret = '7e226a8469b045d493c378e21c20b68d';
  9. /**
  10. * @param $params
  11. * @return string
  12. */
  13. private static function getSign($params): string
  14. {
  15. $key = self::$app_secret;
  16. ksort($params);
  17. $sign = '';
  18. foreach ($params as $ke => $value) {
  19. if ($value !== '') $sign .= sprintf('%s=%s&', $ke, $value);
  20. }
  21. return strtoupper(md5($sign . 'key=' . $key));
  22. }
  23. /**
  24. * @param $mobile
  25. * @param $order_id
  26. * @param $money
  27. * @return mixed
  28. */
  29. public static function fastRecharge($mobile, $order_id, $money)
  30. {
  31. $url = "/api/recharge/server";
  32. $domain = sys_config('site_url', '');
  33. if (strstr($domain, 'http://')) {
  34. $domain = substr($domain, 7);
  35. } else {
  36. $domain = substr($domain, 8);
  37. }
  38. $time = time();
  39. $data = [
  40. 'appId' => self::$app_id,
  41. 'mobile' => $mobile,
  42. 'orderId' => $order_id,
  43. 'amount' => $money,
  44. 'notifyUrl' => sys_config('site_url', '') . '/api/mobile/notify',
  45. 'timestamp' => $time,
  46. 'urlHost' => $domain];
  47. $data['sign'] = self::getSign($data);
  48. $res = do_request(self::$domain . $url, $data);
  49. return json_decode($res, true);
  50. }
  51. /**
  52. * @param $mobile
  53. * @param $order_id
  54. * @param $money
  55. * @return mixed
  56. */
  57. public static function slowRecharge($mobile, $order_id, $money)
  58. {
  59. $url = "/api/rechargeslow/server";
  60. $domain = sys_config('site_url', '');
  61. if (strstr($domain, 'http://')) {
  62. $domain = substr($domain, 7);
  63. } else {
  64. $domain = substr($domain, 8);
  65. }
  66. $time = time();
  67. $data = [
  68. 'appId' => self::$app_id,
  69. 'mobile' => $mobile,
  70. 'orderId' => $order_id,
  71. 'amount' => $money,
  72. 'notifyUrl' => sys_config('site_url', '') . '/api/mobile/notify',
  73. 'timestamp' => $time,
  74. 'urlHost' => $domain];
  75. $data['sign'] = self::getSign($data);
  76. $res = do_request(self::$domain . $url, $data);
  77. return json_decode($res, true);
  78. }
  79. }