在网页中的扫码支付是让js主动轮询服务器的,但是在iOS的APP中,无法使用js,所以需要在PHP中做回调处理
public function wxNotify(){
$this->load->model('User_model');
$order_no = $this->input->post('order_no');
ini_set('date.timezone','Asia/Shanghai');
error_reporting(E_ERROR);
require_once (__DIR__.'/../WXSDK0308/lib/WxPay.Api.php');
require_once (__DIR__.'/../WXSDK0308/example/log.php');
sleep(3);
while($this->query($order_no)=='NOTPAY'){
sleep(1);
$this->query($order_no);
}
if($this->query($order_no)=='SUCCESS'){
$update['from'] = 'orders';
$update['where'] = "order_no= '$order_no' " ;
$update['set'] = array(
'is_pay' => 1,
'pay_time' => time(),
'pay_type' => 'wx',
);
if($this->User_model->updateByCondition($update)){
$info['mess'] = 'ok';
$info['flag'] = 1;
exit(json_encode($info));
}else{
$info['mess'] = 'Fail';
$info['flag'] = 0;
exit(json_encode($info));
}
}
}
public function query($order_no){
if(isset($order_no) && $order_no != ""){
$out_trade_no = $order_no;
$input = new WxPayOrderQuery();
$input->SetOut_trade_no($out_trade_no);
$result=WxPayApi::orderQuery($input);
return $result['trade_state'];
}else{
return 500; // no order_no
}
}