12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace refill\xc;
- require_once(BASE_HELPER_RAPI_PATH . '/xc/config.php');
- use refill;
- use Log;
- class RefillPhone extends refill\IRefillPhone
- {
- public function __construct($cfgs)
- {
- parent::__construct($cfgs);
- }
- private function req_params(int $phone, int $amount ,string $order_sn)
- {
- $params['pay_iphone'] = $phone;
- $params['pay_orderid'] = $order_sn;
- $params['pay_memberid'] = config::NUMBER_ID;
- $params['pay_money'] = $amount;
- $params['pay_notify'] = config::NOTIFY_URL;
- return $params;
- }
- public function add($card_no, $card_type,$amount,$params)
- {
- $order_sn = $params['order_sn'];
- $params = $this->req_params($card_no,$amount,$order_sn);
- $params['sign'] = $this->sign($params);
- $resp = http_request(config::ORDER_URL,$params,'POST');
- if($resp === false) {
- return [false,'系统错误'];
- }
- else
- {
- Log::record($resp,Log::DEBUG);
- $resp = json_decode($resp,true);
- if($resp['code'] == 200 && $resp['result'] == 'SUCCESS') {
- return [true,$resp['result']];
- }
- else {
- return [false,$resp['result']];
- }
- }
- }
- public function query($refill_info){
- $params['pay_orderid'] = $refill_info['order_sn'];
- $params['pay_memberid'] = config::NUMBER_ID;
- $sign = $this->sign($params,true);
- $params['sign'] = $sign;
- $resp = http_request(config::QUERY_ORDER_URL,$params,'POST');
- if($resp === false) {
- return [false,'系统错误'];
- }
- else
- {
- Log::record($resp,Log::DEBUG);
- $resp = json_decode($resp,true);
- $order_state = '';
- if ($resp['status'] == 1) {
- $order_state = ORDER_STATE_SUCCESS;
- } elseif ($resp['status'] == 2) {
- $order_state = ORDER_STATE_CANCEL;
- } elseif ($resp['status'] == 6){
- $order_state = ORDER_STATE_SEND;
- }
- if (empty($order_state)) {
- return [false, $resp['data']];
- }
- return [true, $order_state];
- }
- }
- private function sign($params , $encrypt = false)
- {
- ksort($params);
- $content = '';
- foreach ($params as $key => $val){
- $content .= "{$key}={$val}&";
- }
- if($encrypt){
- $content = md5($content);
- }
- $str = $content . config::KEY;
- return md5($str);
- }
- }
|