diff --git a/webht/third_party/pay/controllers/WxpayService.php b/webht/third_party/pay/controllers/WxpayService.php index ab1efaac..b2a65f58 100644 --- a/webht/third_party/pay/controllers/WxpayService.php +++ b/webht/third_party/pay/controllers/WxpayService.php @@ -165,6 +165,19 @@ class WxpayService extends CI_Controller { return; } + public function query($target_account) + { + $GLOBALS['__WX_SITE_NAME__'] = $target_account; + $this->load->model('WxpayQueryContentBuilder', 'query_builder'); + $this->query_builder->set_transaction_id($this->input->get_post('transaction_id')); + $this->load->library('Wxpay_call'); + $result = $this->wxpay_call->queryorder($this->query_builder); + if ($result['status'] !== true) { + log_message('error',"get wxpay transaction failed. " . PHP_EOL . var_export($result, 1)); + } + return $this->output->set_content_type('application/json')->set_output(json_encode($result)); + } + public function response_to_wx($response_arr) { $response_body = to_xml($response_arr); diff --git a/webht/third_party/pay/libraries/wxpay_call.php b/webht/third_party/pay/libraries/wxpay_call.php index 42aff5a4..7c184e38 100644 --- a/webht/third_party/pay/libraries/wxpay_call.php +++ b/webht/third_party/pay/libraries/wxpay_call.php @@ -25,6 +25,25 @@ class Wxpay_call $this->api_info_arr['app_secret'] = $this->wx_site_config['app_secret']; } + public function queryorder($query_content) + { + $ret = array('status'=>false, 'data'=>array()); + $this->init_api(); + unset($this->api_info_arr['key']); + unset($this->api_info_arr['app_secret']); + $url = "https://api.mch.weixin.qq.com/pay/orderquery"; + $query_content_input = $query_content->getBizContent(true); + $this->api_info_arr['nonce_str'] = ($this->get_nonce_str());//随机字符串 + + $this->api_info_arr['sign'] = $this->make_sign(array_merge($this->api_info_arr, $query_content_input));//签名 + $xml = to_xml(array_merge($this->api_info_arr, $query_content_input)); + + $response = $this->post_xml_curl($this->api_info_arr, $xml, $url, 20); + $ret['status'] = true; + $ret['data'] = from_xml($response); + return $ret; + } + /** * 下载对账单,WxPayDownloadBill中bill_date为必填参数 * appid、mchid、spbill_create_ip、nonce_str不需要填入 diff --git a/webht/third_party/pay/models/WxpayQueryContentBuilder.php b/webht/third_party/pay/models/WxpayQueryContentBuilder.php index ffa56617..5ee76883 100644 --- a/webht/third_party/pay/models/WxpayQueryContentBuilder.php +++ b/webht/third_party/pay/models/WxpayQueryContentBuilder.php @@ -49,6 +49,13 @@ class WxpayQueryContentBuilder extends CI_Model $this->bizContentarr['tar_type'] = $tar_type; } + public function set_transaction_id($transaction_id) + { + $this->transaction_id = $transaction_id; + $this->bizContentarr['transaction_id'] = $transaction_id; + } + + } /* End of file WxpayQueryContentBuilder.php */