12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace crmeb\services;
- use app\models\user\UserMobileRecharge;
- class MobileRechargeService
- {
- private static $domain = 'https://api.nyyun.cn';
- private static $app_id = 'nyeu184mkg';
- private static $app_secret = '7e226a8469b045d493c378e21c20b68d';
- /**
- * @param $params
- * @return string
- */
- private static function getSign($params): string
- {
- $key = self::$app_secret;
- ksort($params);
- $sign = '';
- foreach ($params as $ke => $value) {
- if ($value !== '') $sign .= sprintf('%s=%s&', $ke, $value);
- }
- return strtoupper(md5($sign . 'key=' . $key));
- }
- /**
- * @param $mobile
- * @param $order_id
- * @param $money
- * @return mixed
- */
- public static function fastRecharge($mobile, $order_id, $money)
- {
- $url = "/api/recharge/server";
- $domain = sys_config('site_url', '');
- if (strstr($domain, 'http://')) {
- $domain = substr($domain, 7);
- } else {
- $domain = substr($domain, 8);
- }
- $time = time();
- $data = [
- 'appId' => self::$app_id,
- 'mobile' => $mobile,
- 'orderId' => $order_id,
- 'amount' => $money,
- 'notifyUrl' => sys_config('site_url', '') . '/api/mobile/notify',
- 'timestamp' => $time,
- 'urlHost' => $domain];
- $data['sign'] = self::getSign($data);
- $res = do_request(self::$domain . $url, $data);
- return json_decode($res, true);
- }
- /**
- * @param $mobile
- * @param $order_id
- * @param $money
- * @return mixed
- */
- public static function slowRecharge($mobile, $order_id, $money)
- {
- $url = "/api/rechargeslow/server";
- $domain = sys_config('site_url', '');
- if (strstr($domain, 'http://')) {
- $domain = substr($domain, 7);
- } else {
- $domain = substr($domain, 8);
- }
- $time = time();
- $data = [
- 'appId' => self::$app_id,
- 'mobile' => $mobile,
- 'orderId' => $order_id,
- 'amount' => $money,
- 'notifyUrl' => sys_config('site_url', '') . '/api/mobile/notify',
- 'timestamp' => $time,
- 'urlHost' => $domain];
- $data['sign'] = self::getSign($data);
- $res = do_request(self::$domain . $url, $data);
- return json_decode($res, true);
- }
- }
|