RefillPhone.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace refill\bjbnew;
  3. require_once(BASE_HELPER_RAPI_PATH . '/bjbnew/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['chargenumbertype'] = 1;
  15. $params['agentid'] = config::AGENT_ID;
  16. $params['returntype'] = 2;
  17. $params['orderid'] = $order_sn;
  18. $params['chargenumber'] = $phone;
  19. $params['amountmoney'] = $amount;
  20. $params['source'] = 2;
  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. $params['orderid'] = $refill_info['order_sn'];
  31. $params['agentid'] = config::AGENT_ID;
  32. $params['returntype'] = 2;
  33. $key = config::MerchantKey;
  34. $content = "agentid={$params['agentid']}&returntype={$params['returntype']}&orderid={$params['orderid']}&merchantKey={$key}";
  35. $params['verifystring'] = md5($content);
  36. $resp = http_request(config::QUERY_URL,$params);
  37. if (empty($resp)) {
  38. return [false,'系统错误'];
  39. }
  40. else
  41. {
  42. Log::record($resp,Log::DEBUG);
  43. $resp = $this->xmlToArray($resp);
  44. if (empty($resp)) {
  45. return [false, '系统错误'];
  46. } elseif ($resp['resultno'] == 0014) {
  47. $order_state = ORDER_STATE_SUCCESS;
  48. } elseif ($resp['resultno'] == 0015) {
  49. $order_state = ORDER_STATE_CANCEL;
  50. } elseif ($resp['resultno'] == 0016) {
  51. $order_state = ORDER_STATE_SEND;
  52. } else {
  53. return [false, $resp['resultmessage']];
  54. }
  55. return [true, $order_state];
  56. }
  57. }
  58. public function balance()
  59. {
  60. return [false, '暂无余额接口'];
  61. }
  62. private function sign($params)
  63. {
  64. $key = config::MerchantKey;
  65. $content = "chargenumbertype={$params['chargenumbertype ']}&agentid={$params['agentid']}&returntype={$params['returntype']}&orderid={$params['orderid']}";
  66. $content .= "chargenumber={$params['chargenumber']}&amountmoney={$params['amountmoney']}&ispname={$params['ispname']}&source={$params['source']}&merchantKey={$key}";
  67. return md5($content);
  68. }
  69. private function xmlToArray($xml)
  70. {
  71. //禁止引用外部xml实体
  72. libxml_disable_entity_loader(true);
  73. $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
  74. $val = json_decode(json_encode($xmlstring), true);
  75. return $val;
  76. }
  77. }