const NOTIFY_URL = 'http://pay.gbicom.cn/index.php/dispatch/weixinNotify';
/*
* 生成支付二维码
*/
public function createCodeAction(){
$ContractNumber = $this->request['order_card'];
$SysOrderModel = new SysOrderModel();
$where['ContractNumber'] = $ContractNumber;
$data = $SysOrderModel->getOne($where);
if(!empty($data) && ($data['order_total_fee'] - $data['order_coupons_money']) <= $data['order_pay_money']){
Tools::redirect('http://home.gbicom.cn/order/paySuccess?connum='.$ContractNumber);
exit;
}
$u_sn = $data['ContractNumber'].'_'.($data['order_total_fee'])*100;
$param = array(
'attach' => base64_encode($data['ContractNumber']),
'body' => $data['ContractNumber'],
'out_trade_no' => $u_sn.'_'.time(),
'total_fee' => ($data['order_total_fee'])*100,
'spbill_create_ip' => $_SERVER['REMOTE_ADDR'],
'trade_type' => 'NATIVE',
'product_id' => rand(),
);
try
{
$redis = new common_Redis($host = '127.0.0.1', $port = 6379);
$g_data = $redis->get($u_sn);
if(!empty($g_data))
{
$codeUrl = $g_data;
}
else
{
// $order = new Order();
// $order->close($u_sn);
$code = new Qrcode();
$codeUrl = $code->interim($param);
$redis->setex($u_sn,$codeUrl,7200);
}
}
catch (WxException $ex)
{
$ex->showError();
}
$ret = array('code'=>200,'msg'=>$codeUrl);
$ret = json_encode($ret);
echo $ret;
}
//回调地址处理逻辑
public function weixinNotifyAction(){
try
{
$xml = file_get_contents('php://input', 'r');
Log::record('[微信支付成功后返回的数据xml]:' . $xml, Log::LOG_LEVEL_DEBUG);
$payInfo = Xml::xmlToArr($xml);
Sign::verify($payInfo);
$out_trade_no = $payInfo['out_trade_no'];
$out_trade_no = explode('_', $out_trade_no);
if(count($out_trade_no) > 2)
{
array_pop($out_trade_no);
$payInfo['out_trade_no'] = join('_',$out_trade_no);
}
$log = new PaylogModel() ;
$log ->add(array('channel'=> 4,'json' => 'yibu'.json_encode($payInfo)));
$channelId = SetupNotifyModel::CHANNEL_WEIXIN;
$payInfo['appId'] = 13;
$payInfo['channelId'] = $channelId;
$cWeixin = new WxpayController();
$result = $cWeixin->notify($payInfo);
}
catch (WxException $ex)
{
$ex->showError();
}
}
/*
* 支付异步通知方法
*/
public function notify($payInfo) {
$log = new PaylogModel() ;
$log->add(array('channel'=>4,'json' => 'weixin_notify_url###'.json_encode($payInfo)));
//Sign::verify($payInfo);
if ($payInfo['result_code'] == 'SUCCESS')
{
$res = common_NotifyOrder::notifyweixin(self::PAY_STATUS_URL, $payInfo);
$log->add(array('json'=>json_encode($res)));
$res = (array)$res;
if($res['errorCode'] == 1)
{
$this->payBook($payInfo);
$ret = array('return_code'=>'SUCCESS');
}
else
{
$ret = array('return_code'=>'FAIL','return_msg'=>'CRM Send Fail');
$log->add(array('json' => 'CRM Send Fail'));
}
}
else
{
$ret = array('return_code'=>'FAIL','return_msg'=>'Bussiness Error');
$log->add(array('json' => 'Bussiness Error'));
}
$xml = Xml::arrToXml($ret);
Log::record('[送给微信的回调信息]: ' . $xml, Log::LOG_LEVEL_DEBUG);
header("Content-type:text/xml");
echo $xml;
}