RefillPhone.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace refill\yifa;
  3. require_once(BASE_HELPER_RAPI_PATH . '/yifa/config.php');
  4. use refill;
  5. use Log;
  6. class RefillPhone extends refill\IRefillPhone
  7. {
  8. public function __construct($cfgs)
  9. {
  10. parent::__construct($cfgs);
  11. }
  12. private function req_params(int $phone, int $amount ,string $order_sn)
  13. {
  14. $params['app_id'] = config::APP_ID;
  15. $params['nonce_str'] = strtoupper($this->createNoncestr());
  16. $params['timestamp'] = time();
  17. $params['order_sn'] = $order_sn;
  18. $params['phone'] = $phone;
  19. $params['amount'] = $amount;
  20. $params['notify_url'] = config::NOTIFY_URL;
  21. return $params;
  22. }
  23. public function add($card_no, $card_type,$amount,$params,&$net_errno = 0)
  24. {
  25. refill\util::send_normal($params['order_sn']);
  26. return [true , '',false];
  27. }
  28. public function query($refill_info)
  29. {
  30. }
  31. public function balance()
  32. {
  33. return [false, '暂无余额接口'];
  34. }
  35. /**
  36. * 作用:产生随机字符串,不长于32位
  37. */
  38. public function createNoncestr( $length = 32 )
  39. {
  40. $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
  41. $str ="";
  42. for ( $i = 0; $i < $length; $i++ ) {
  43. $str.= substr($chars, mt_rand(0, strlen($chars)-1), 1);
  44. }
  45. return $str;
  46. }
  47. private function sign($params)
  48. {
  49. ksort($params);
  50. $app_secret = config::APP_SECRET;
  51. $content = $app_secret;
  52. foreach ($params as $key => $val)
  53. {
  54. if(empty($val)){
  55. continue;
  56. }
  57. $content .= "{$key}{$val}";
  58. }
  59. $content .= $app_secret;
  60. return strtoupper(md5($content));
  61. }
  62. }