ecshop開發網站,如果沒有手機版,又想通過微信支付,可以加入pc二維碼掃描微信支付功能
方法/步驟
-
使用PHP QR Code生成二維碼,下載,在商品支付頁面加入
include 'phpqrcode/phpqrcode.php';
$pay_url ='http://www.xxx.com/weixin/weixin.php?order_id='.$order['order_sn'];
QRcode::png($pay_url, 'images/image.png', 'L', 8);
echo '<img src="images/image.png" />';
生成一個指向微信支付的手機連接二維碼,手機掃描進入
-
打開申請到的微信支付代碼,在上面加入weixin.php
define('IN_ECS', true);
require('../includes/init.php');
require('../includes/lib_order.php');
$order_id = isset($_GET['order_id']) ? intval($_GET['order_id']) : 0;
$order = order_info(0,$order_id);
獲取訂單信息
-
手機打開頁面調用代碼
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>微信安全支付</title>
<script type="text/javascript">
//調用微信JS api 支付
function jsApiCall()
{
WeixinJSBridge.invoke(
'getBrandWCPayRequest',
<?php echo $jsApiParameters; ?>,
function(res){
WeixinJSBridge.log(res.err_msg);
//alert(res.err_code+res.err_desc+res.err_msg);
}
);
}
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();
}
}
callpay();
</script>
</head>
<body>
</br></br></br></br>
</body>
</html>
-
代碼引用WxPayPubHelper,
WxPay.pub.config.php
配置文件
class WxPayConf_pub
{
//=======【基本信息設置】=====================================
//微信公眾號身份的唯一標識。審核通過后,在微信發送的郵件中查看
const APPID = 'xxx';
//受理商ID,身份標識
const MCHID = 'xxx';
//商戶支付密鑰Key。審核通過后,在微信發送的郵件中查看
const KEY = 'xxx';
//JSAPI接口中獲取openid,審核后在公眾平台開啟開發模式后可查看
const APPSECRET = 'xxx';
//=======【JSAPI路徑設置】===================================
//獲取access_token過程中的跳轉uri,通過跳轉將code傳入jsapi支付頁面
const JS_API_CALL_URL = 'http://www.xxx.com/weixin/js_api_call.php';
//=======【證書路徑設置】=====================================
//證書路徑,注意應該填寫絕對路徑
const SSLCERT_PATH = '/weixin/WxPayPubHelper/cacert/apiclient_cert.pem';
const SSLKEY_PATH = '/weixin/WxPayPubHelper/cacert/apiclient_key.pem';
//=======【異步通知url設置】===================================
//異步通知url,商戶根據實際開發過程設定
const NOTIFY_URL = 'http://www.xxx.com/weixin/notify_url.php';
//=======【curl超時設置】===================================
//本例程通過curl使用HTTP POST方法,此處可修改其超時時間,默認為30秒
const CURL_TIMEOUT = 30;
}
?>
根據申請的信息填寫
-
找到notify_url.php文件
上面添加
define('IN_ECS', true);
require('../includes/init.php');
require('../includes/lib_payment.php');
調用訂單信息
-
notify_url.php添加支付后修改訂單狀態
if($notify->checkSign() == TRUE)
{
if ($notify->data["return_code"] == "FAIL") {
//此處應該更新一下訂單狀態,商戶自行增刪操作
//$log_->log_result($log_name,"【通信出錯】:\n".$xml."\n");
}
elseif($notify->data["result_code"] == "FAIL"){
//此處應該更新一下訂單狀態,商戶自行增刪操作
//$log_->log_result($log_name,"【業務出錯】:\n".$xml."\n");
}
else{
//此處應該更新一下訂單狀態,商戶自行增刪操作
//$log_->log_result($log_name,"【支付成功】:\n".$xml."\n");
$order = $notify->getData();
$log_id=get_order_id_by_sn($order["out_trade_no"]);
order_paid($log_id);
}
//商戶自行增加處理流程,
//例如:更新訂單狀態
//例如:數據庫操作
//例如:推送支付完成信息
}
-
更多安全信息和詳細信息就不列舉了