ecshop增加pc扫描二维码微信支付功能代码

2025-10-19 18:34:39

1、使用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" />';

生成一个指向微信支付的手机连接二维码,手机扫描进入

ecshop增加pc扫描二维码微信支付功能代码

2、打开申请到的微信支付代码,在上面加入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);

获取订单信息

ecshop增加pc扫描二维码微信支付功能代码

3、手机打开页面调用代码

<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>

ecshop增加pc扫描二维码微信支付功能代码

4、代码引用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;

}

?>

根据申请的信息填写

ecshop增加pc扫描二维码微信支付功能代码

5、找到notify_url.php文件

上面添加

define('IN_ECS', true);

require('../includes/init.php');

require('../includes/lib_payment.php');

调用订单信息

ecshop增加pc扫描二维码微信支付功能代码

6、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);

}

//商户自行增加处理流程,

//例如:更新订单状态

//例如:数据库操作

//例如:推送支付完成信息

}

ecshop增加pc扫描二维码微信支付功能代码

7、更多安全信息和详细信息就不列举了

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢