// | CreateTime : 2018 // +---------------------------------------------------------------------- namespace Pay\Controller; use Vendor\Yunpay\YunPay; class YunPayController extends Controller{ /** * 支付成员变量 * @Author Bieanju **/ public $orderId,$out_trade_no,$trade_no,$yunprice; public function _initialize() { parent::_initialize(); header("Content-Type:text/html; charset=utf-8"); } /** * 腾讯云支付 * @Author Bieanju **/ public function yunpay(){ $model = D("Order"); $where['id'] = $this->orderId ; $order = $model->where($where)->field('number,buy_sn,pay_amount,buy_status')->find(); $out_trade_no = $order['buy_sn'];//商户订单号,必填 $subject = "支付[订单编号:".$out_trade_no."]支付测试";//必填 $total_fee = $order['pay_amount'];//必填 需为整数 $body = $subject; $parameter = array( "partner" => trim(C("yunpay_config.partner")), "seller_email" => C("yunpay_config.seller_email"), "out_trade_no" => $out_trade_no, "subject" => $subject, "total_fee" => $total_fee, "body" => $body, "nourl" => C("yunpay.notify"), "reurl" => C("yunpay.return"), "orurl" => "", "orimg" => "" ); $YunPayObj = new YunPay(); $html_text = $YunPayObj->i2e($parameter, "支付进行中..."); echo $html_text; } /** * 同步通知 * @Author Bieanju **/ public function returnUrl(){ //计算得出通知验证结果 $YunPayObj = new YunPay(); $yunNotify = $YunPayObj->md5Verify($_REQUEST['i1'],$_REQUEST['i2'],$_REQUEST['i3']); if($yunNotify) { $this->out_trade_no = $_REQUEST['i2']; $this->trade_no = $_REQUEST['i4']; $this->yunprice=$_REQUEST['i1']; self::afterPayLogic() && self::payLog(); } else { echo "验证失败"; } } /** * 异步通知 * @Author Bieanju **/ public function notifyUrl(){ $YunPayObj = new YunPay(); //计算得出通知验证结果 $yunNotify = $YunPayObj->md5Verify($_REQUEST['i1'],$_REQUEST['i2'],$_REQUEST['i3']); if($yunNotify) { echo "success"; }else { echo "fail"; } } /** * 支付完成更新数据 * @Author Bieanju **/ private function afterPayLogic(){ $model = D("Order");$where['buy_sn'] = $this->out_trade_no; $orderInfo = $model->where($where)->getField('sale_sn'); $result = $model->where(array("sale_sn"=>$orderInfo))->setField('status',2); return $result !== false ? true : false; } /** * 日志记录 * @Author Bieanju **/ private function payLog(){ $model = D("MemberPayLog"); /* data post */ $data['uid'] = $this->userid; $data['pay_no'] = $this->out_trade_no; $data['type'] = 0; $data['create_time'] = time(); $data['amount'] = $this->yunprice; $data['trade_no'] = $this->trade_no; /* end */ return $model->add($data) ? true : false; } } ?>