Server : Apache System : Linux iZ2vcgyutqttsd1p850kl8Z 3.10.0-1160.92.1.el7.x86_64 #1 SMP Tue Jun 20 11:48:01 UTC 2023 x86_64 User : www ( 1000) PHP Version : 5.6.40 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv Directory : /www/wwwroot/saimikebio.com/mobile/include/modules/payment/ |
<?php if (!defined('IN_ECTOUCH')) { die('Hacking attempt'); } // 包含配置文件 $payment_lang = ROOT_PATH . 'lang/' . $GLOBALS['_CFG']['lang'] . '/payment/'. basename(__FILE__); if (file_exists($payment_lang)) { global $_LANG; include_once($payment_lang); } /* 模块的基本信息 */ if (isset($set_modules) && $set_modules == TRUE) { $i = isset($modules) ? count($modules) : 0; /* 代码 */ $modules[$i]['code'] = basename(__FILE__, '.php'); /* 描述对应的语言项 */ $modules[$i]['desc'] = 'wxpay_h5_desc'; /* 是否支持货到付款 */ $modules[$i]['is_cod'] = '0'; /* 是否支持在线支付 */ $modules[$i]['is_online'] = '1'; /* 作者 */ $modules[$i]['author'] = 'ECSHOP教程网'; /* 网址 */ $modules[$i]['website'] = 'http://www.ecshopjcw.com/'; /* 版本号 */ $modules[$i]['version'] = '1.0'; /* 配置信息 */ $modules[$i]['config'] = array( // 微信公众号身份的唯一标识 array( 'name' => 'wxpay_h5_appid', 'type' => 'text', 'value' => '' ), // JSAPI接口中获取openid,审核后在公众平台开启开发模式后可查看 array( 'name' => 'wxpay_h5_appsecret', 'type' => 'text', 'value' => '' ), // 商户ID array( 'name' => 'wxpay_h5_mchid', 'type' => 'text', 'value' => '' ), // 商户支付密钥Key array( 'name' => 'wxpay_h5_key', 'type' => 'text', 'value' => '' ) ); return; } $lib_path = dirname(__FILE__).'/wxpay/'; require_once $lib_path."WxPay.Config.php"; require_once $lib_path."WxPay.Api.php"; require_once $lib_path."WxPay.Notify.php"; require_once $lib_path."WxPay.JsApiPay.php"; require_once $lib_path."log.php"; /** * 微信支付类 */ class wxpay_h5 { private $dir ; private $site_url; function _config( $payment ) { WxPayConfig::set_appid( $payment['wxpay_h5_appid'] ); WxPayConfig::set_mchid( $payment['wxpay_h5_mchid'] ); WxPayConfig::set_key( $payment['wxpay_h5_key'] ); WxPayConfig::set_appsecret( $payment['wxpay_h5_appsecret']); } /** * 生成支付代码 * @param array $order 订单信息 * @param array $payment 支付方式信息 */ function get_code($order, $payment, $go = 0) { $root_url = $GLOBALS['ecs']->url(); $dir_file = $_SERVER['SCRIPT_NAME']; $filename = basename($dir_file); $openId = $_SESSION['wxpay_jspay_openid']; $spbill_create_ip = $this->get_real_ip(); //var_dump($spbill_create_ip); $this->_config($payment); $root_url = $GLOBALS['ecs']->url(); //$root_url = str_replace('mobile/', '', $root_url); $notify_url = $root_url.'wxpay_h5_notify.php'; $query_url = $root_url.'wxpay_h5.php?act=order_query'; $return_url = $GLOBALS['ecs']->url().'respond.php?code='.basename(__FILE__, '.php'); $return_url = return_url(basename(__FILE__, '.php')); $out_trade_no = $order['order_sn'] . 'O' . $order['log_id']. 'O' . date('is'); $body = $order['order_sn']; $sql = "select * from " . $GLOBALS['ecs']->table('pay_log') . " WHERE log_id = '". $order['log_id'] ."' "; $pay_log = $GLOBALS['db']->getRow($sql); if (!empty( $pay_log ) ){ if ( $pay_log['order_type'] == 0 ){ //$sql = "select goods_name from " . $GLOBALS['ecs']->table('order_goods') . " WHERE order_id = '". $pay_log['order_id'] ."' "; //$body = $GLOBALS['db']->getOne($sql); //$body = $this->msubstr($body,0, 20); $body = '订单号:'.$order['order_sn']; } elseif ($pay_log['order_type'] == 1 ){ $body = '在线充值'; } } //统一下单 $tools = new JsApiPay(); $input = new WxPayUnifiedOrder(); $input->SetBody( $body ); $input->SetAttach( $order['log_id'] ); //商户支付日志 $input->SetOut_trade_no( $out_trade_no ); //商户订单号 $input->SetTotal_fee( strval(($order['order_amount']*100)) ); //总金额 $input->SetTime_start(date("YmdHis")); //$input->SetTime_expire(date("YmdHis", time() + 600)); //$input->SetGoods_tag("test"); $input->SetSpbill_create_ip( $spbill_create_ip); $input->SetNotify_url( $notify_url ); //通知地址 $input->SetTrade_type("MWEB"); //交易类型 $input->SetProduct_id( $order['order_sn'] ); //$input->SetOpenid($openId); $result = WxPayApi::unifiedOrder($input); if ( $result['return_code'] == 'FAIL' ){ $error = $result['return_msg']; return $this->return_error($error); } if ( $result['result_code'] == 'FAIL' ){ $error = $result['err_code'].' '.$result['err_code_des']; return $this->return_error($error); } if ( empty($result['mweb_url']) ){ $error = '获取支付mweb_url失败'; return $this->return_error($error); } $mweb_url = $result['mweb_url']; //$mweb_url .= '&redirect_url='.urlencode($return_url); $script .='<script type="text/javascript"> function get_wxpay_status( id ){ jQuery.get("'. $query_url .'", "pay_code=wxpay_h5&id="+id,function( result ){ if ( result.error == 0 && result.is_paid == 1 ){ window.location.href = result.url; } }, "json"); } function return_wxpay_order_status( result ){ if ( result.error == 0 && result.is_paid == 1 ){ window.location.href = result.url; } } window.setInterval(function(){ get_wxpay_status("'. $order['log_id'] .'"); }, 2000); </script>'; $html = '<a id="pay_wxpay" class="box-flex btn-submit c-btn6" href="'.$mweb_url.'" >' .$GLOBALS['_LANG']['wxpay_h5_button']. '</a>'; return $html.$script; } function respond() { return true; } function notify() { $payment = get_payment('wxpay_h5'); $this->_config($payment); $lib_path = dirname(__FILE__).'/wxpay/'; $logHandler= new CLogFileHandler($lib_path."logs/".date('Y-m-d').'.log'); $log = Log::Init($logHandler, 15); Log::DEBUG("begin notify"); $notify = new H5PayNotifyCallBack( ); $notify->Handle(true); $data = $notify->data; //判断签名 if ($data['result_code'] == 'SUCCESS') { $transaction_id = $data['transaction_id']; // 获取log_id $out_trade_no = explode('O', $data['out_trade_no']); $order_sn = $out_trade_no[0]; $log_id = (int)$out_trade_no[1]; // 订单号log_id $payment_amount = $data['total_fee']/100; /* 检查支付的金额是否相符 */ if (!check_money($log_id, $payment_amount)) { echo 'fail'; return false; } $action_note = 'result_code' . ':' . $data['result_code'] . ' return_code:' . $data['return_code'] . ' orderId:' . $data['out_trade_no'] . ' openid:' . $data['openid'] . ' '.$GLOBALS['_LANG']['wxpay_jspay_transaction_id'] . ':' . $transaction_id; // 完成订单。 order_paid($log_id, PS_PAYED, $action_note); return true; }else{ //echo 'fail'; return false; } return false; } /** * 字符串截取,支持中文和其他编码 * @static * @access public * @param string $str 需要转换的字符串 * @param string $start 开始位置 * @param string $length 截取长度 * @param string $charset 编码格式 * @param string $suffix 截断显示字符 * @return string */ function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true) { if(function_exists("mb_substr")) $slice = mb_substr($str, $start, $length, $charset); elseif(function_exists('iconv_substr')) { $slice = iconv_substr($str,$start,$length,$charset); }else{ $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/"; $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/"; $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/"; $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/"; preg_match_all($re[$charset], $str, $match); $slice = join("",array_slice($match[0], $start, $length)); } return $suffix ? $slice.'...' : $slice; } function return_error( $error ){ $html = '<a type="button" class="box-flex btn-submit c-btn6" onclick="javascript:alert(\''. $error .'\')">' .$GLOBALS['_LANG']['wxpay_h5_button']. '</a>'; return $html; } function get_real_ip() { global $ip; if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP"); else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR"); else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR"); else $ip = "Unknow"; return $ip; } } class H5PayNotifyCallBack extends WxPayNotify { public $data; //查询订单 public function Queryorder($transaction_id) { $input = new WxPayOrderQuery(); $input->SetTransaction_id($transaction_id); $result = WxPayApi::orderQuery($input); Log::DEBUG("query:" . json_encode($result)); if(array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { return true; } return false; } //重写回调处理函数 public function NotifyProcess($data, &$msg) { Log::DEBUG("call back:" . json_encode($data)); $this->data = $data; $notfiyOutput = array(); if(!array_key_exists("transaction_id", $data)){ $msg = "输入参数不正确"; return false; } //查询订单,判断订单真实性 if(!$this->Queryorder($data["transaction_id"])){ $msg = "订单查询失败"; return false; } return true; } } ?>