PHP后台支付的开发:微信支付和支付宝支付( 三 )


$mes = array(
'return_code' => 'SUCCESS',
'return_msg' => 'OK'
);
$this->ajaxReturn($mes, 'XML');
}
//将XML转为array
public function xmlToArray($xml) {
//禁止引用外部xml实体
libxml_disable_entity_loader(true);
$values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $values;
}
}
?>
4.前端微信支付页面wxpay.html
 
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link href=https://www.isolves.com/it/cxkf/yy/php/2019-07-02/"__TMPL__Public/css/weui.css" type="text/css" rel="stylesheet"/>
<title>微信订单支付</title>
<script type="text/JAVAscript">
//调用微信JS api 支付
function jsApiCall()
{
WeixinJSBridge.invoke(
'getBrandWCPayRequest',
<php> echo $jsApiParameters; </php>,
function(res) {
WeixinJSBridge.log(res.err_msg);
if (res.err_msg == "get_brand_wcpay_request:ok") {
// alert(res.err_code + res.err_desc + res.err_msg);
// 成功跳转页面
window.location.href = https://www.isolves.com/it/cxkf/yy/php/2019-07-02/'{:U("Orders/pay_ok",array("o_id"=>$o_id))}';
} else {
// 统一跳转
}
}
);
}
function callpay()
{
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', jsApiCall);
document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
}
} else {
jsApiCall();
}
}
</script>
</head>
<body>
<br/>
<div class="container" id="container"><div class="msg">
<div class="weui_msg">
<div class="weui_icon_area"><i class="weui_icon_success weui_icon_msg"></i></div>
<div class="weui_text_area">
<h2 class="weui_msg_title">订单已生成</h2>
<p class="weui_msg_desc">该笔订单支付金额为:<php> echo $pay_price;</php></p>
</div>
<div class="weui_opr_area">
<p class="weui_btn_area">
<a href="JavaScript:;" class="weui_btn weui_btn_primary" onclick="callpay()">立即支付</a>
<!--<a href=https://www.isolves.com/it/cxkf/yy/php/2019-07-02/"{:U('Order/pay_ok',array('o_id'=>$_GET['o_id']))}" class="weui_btn weui_btn_default">取消支付-->
</p>
</div>
<!-- <div class="weui_extra_area">
<a href=https://www.isolves.com/it/cxkf/yy/php/2019-07-02/"/wap/order/order_det/.html">查看详情
</div>-->
</div>
</div>
</div>
</body>
</html>
5.支付成功跳转到OrderController.class.php,订单支付完成
 
/**
* 支付页面
*/
public function pay_ok() {
$o_id = I("get.o_id", 0, "intval");
$info = $this->model->findone(array("a.id" => $o_id, 'a.status' => array('neq', '-1')));
if (empty($info)) {
# 获取最新可用的商品编号
$goods = D('Goods')->where(array('status' => '1'))->order('id desc')->find();
$this->error("该订单不存在,请重新正确进入", U('Goods/sale', array('id' => $goods['id'])));
}
$this->assign('imgurl', "/wine/img/ok.png");
$this->assign('tips', "订购成功");
if ('4' == $info['pay_id']) {
//微信支付成功
$this->assign($info);
$this->display();
} else {
$this->assign($info);
$this->assign('tips', "订购失败");
$this->assign('imgurl', "/wine/img/nook.png");
$this->display();
}
}
到此,微信支付流程结束 。

  • 支付宝支付
话不多说,直接上代码!
注:1.支付文件是从支付宝上直接拿过来的2.依旧是TP框架【1】将文件放入第三方类库: 
(1)
* 类名:AlipayConfig.php


推荐阅读