<?php
require_once
(
"codepay_config.php"
);
if
(
empty
(
$_POST
))
$_POST
=
$_GET
;
$user
=
$_POST
['user'];
$pay_id
=
$user
;
$price
= (float)
$_POST
[
"price"
];
$param
= '';
$type
= (int)
$_POST
[
"type"
];
if
(
$type
< 1)
$type
= 1;
if
(
$price
<= 0)
$price
= (float)
$_POST
[
"money"
];
$codepay_path
=
$codepay_config
['path'];
if
(
$price
<
$codepay_config
['min'])
exit
('最低限制' .
$codepay_config
['min'] . '元');
$price
= number_format(
$price
, 2, '.', '');
if
(
empty
(
$codepay_config
) || (int)
$codepay_config
['id'] <= 1) {
exit
('请修改配置文件codepay_config.php 或进入<a href=
"install.php"
>install.php</a> 安装码支付接口测试数据');
}
if
(
empty
(
$pay_id
)&&
empty
(
$_POST
['pay_id']))
exit
('需要充值的用户唯一标识不能为空');
if
(
$codepay_config
['pay_type'] == 1 &&
$type
== 1)
$codepay_config
[
"qrcode_url"
] = '';
function
getIp()
{
static
$realip
;
if
(isset(
$_SERVER
)) {
if
(isset(
$_SERVER
['HTTP_X_FORWARDED_FOR'])) {
$realip
=
$_SERVER
['HTTP_X_FORWARDED_FOR'];
}
else
{
$realip
= isset(
$_SERVER
['HTTP_CLIENT_IP']) ?
$_SERVER
['HTTP_CLIENT_IP'] :
$_SERVER
['REMOTE_ADDR'];
}
}
else
{
if
(
getenv
('HTTP_X_FORWARDED_FOR')) {
$realip
=
getenv
('HTTP_X_FORWARDED_FOR');
}
else
{
$realip
=
getenv
('HTTP_CLIENT_IP') ?
getenv
('HTTP_CLIENT_IP') :
getenv
('REMOTE_ADDR');
}
}
return
$realip
;
}
if
(
$_POST
['sign']){
ksort(
$_POST
);
reset(
$_POST
);
$sign
= '';
foreach
(
$_POST
AS
$key
=>
$val
) {
if
(
$val
== '' ||
$key
== 'sign')
continue
;
if
(
$sign
)
$sign
.= '&';
$sign
.=
"$key=$val"
;
}
if
(md5(
$sign
.
$codepay_config
['key']) !=
$_POST
['sign']) {
exit
('签名验证失败');
}
else
{
$parameter
=
$_POST
;
}
}
else
{
$parameter
=
array
(
"id"
=> (int)
$codepay_config
['id'],
"type"
=>
$type
,
"price"
=> (float)
$price
,
"pay_id"
=>
$pay_id
,
"param"
=>
$param
,
"act"
=> (int)
$codepay_config
['act'],
"outTime"
=> (int)
$codepay_config
['outTime'],
"page"
=> (int)
$codepay_config
['page'],
"return_url"
=>
$codepay_config
[
"return_url"
],
"notify_url"
=>
$codepay_config
[
"notify_url"
],
"style"
=> (int)
$codepay_config
['style'],
"pay_type"
=>
$codepay_config
['pay_type'],
"user_ip"
=> getIp(),
"qrcode_url"
=>
$codepay_config
['qrcode_url'],
"chart"
=> trim(
strtolower
(
$codepay_config
['chart']))
);
}
function
create_link(
$params
,
$codepay_key
,
$host
=
""
)
{
ksort(
$params
);
reset(
$params
);
$sign
= '';
$urls
= '';
foreach
(
$params
AS
$key
=>
$val
) {
if
(
$val
== '')
continue
;
if
(
$key
!= 'sign') {
if
(
$sign
!= '') {
$sign
.=
"&"
;
$urls
.=
"&"
;
}
$sign
.=
"$key=$val"
;
$urls
.=
"$key="
. urlencode(
$val
);
}
}
$key
= md5(
$sign
.
$codepay_key
);
$query
=
$urls
. '&sign=' .
$key
;
$apiHost
= (
$host
?
$host
:
"http://api2.fateqq.com:52888/creat_order/?"
); //网关
$url
=
$apiHost
.
$query
;
return
array
(
"url"
=>
$url
,
"query"
=>
$query
,
"sign"
=>
$sign
,
"param"
=>
$urls
);
}
$back
= create_link(
$parameter
,
$codepay_config
['key']);
switch
((int)
$type
) {
case
1:
$typeName
= '支付宝';
break
;
case
2:
$typeName
= 'QQ';
break
;
default
:
$typeName
= '微信';
}
$user_data
=
array
(
"return_url"
=>
$parameter
[
"return_url"
],
"type"
=>
$parameter
['type'],
"outTime"
=>
$parameter
[
"outTime"
],
"codePay_id"
=>
$parameter
[
"id"
],
"out_trade_no"
=>
$parameter
[
"param"
],
"price"
=>
$parameter
['price'],
'money'=>
$parameter
['price'],
'order_id'=>
$parameter
[
"param"
],
"subject"
=>'',
);
$user_data
[
"qrcode_url"
] =
$codepay_config
[
"qrcode_url"
];
$user_data
[
"logoShowTime"
] =
$user_data
[
"qrcode_url"
]?1:2*1000;
if
(
$parameter
['page'] != 3) {
$parameter
['page'] =
"4"
;
$back
= create_link(
$parameter
,
$codepay_config
['key'],
$codepay_config
['gateway']);
if
(function_exists('
file_get_contents
')) {
$codepay_json
=
file_get_contents
(
$back
['url']);
}
else
if
(function_exists('curl_init')) {
$ch
= curl_init();
$timeout
= 5;
curl_setopt(
$ch
, CURLOPT_URL,
$back
['url']);
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER, 1);
curl_setopt(
$ch
, CURLOPT_CONNECTTIMEOUT,
$timeout
);
$codepay_json
= curl_exec(
$ch
);
curl_close(
$ch
);
}
}
if
(
empty
(
$codepay_json
)) {
$parameter
['call'] =
"callback"
;
$parameter
['page'] =
"3"
;
$back
= create_link(
$parameter
,
$codepay_config
['key'], 'https:
$codepay_html
= '<script src=
"' . $back['url'] . '"
></script>';
}
else
{
$codepay_data
= json_decode(
$codepay_json
);
$qr
=
$codepay_data
?
$codepay_data
->qrcode : '';
$codepay_html
=
"<script>callback({$codepay_json})</script>"
;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=<?php echo $codepay_config['chart'] ?>"
>
<meta http-equiv=
"Content-Language"
content=
"zh-cn"
>
<meta name=
"apple-mobile-web-app-capable"
content=
"no"
/>
<meta name=
"apple-touch-fullscreen"
content=
"yes"
/>
<meta name=
"format-detection"
content=
"telephone=no,email=no"
/>
<meta name=
"apple-mobile-web-app-status-bar-style"
content=
"white"
>
<meta name=
"viewport"
content=
"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
>
<title><?php
echo
$typeName
?>扫码支付</title>
<link href=
"<?php echo $codepay_path ?>/css/wechat_pay.css"
rel=
"stylesheet"
media=
"screen"
>
<link href=
"<?php echo $codepay_path?>/css/toastr.min.css"
rel=
"stylesheet"
>
<link href=
"<?php echo $codepay_path?>/css/font-awesome.min.css"
rel=
"stylesheet"
>
</head>
<body>
<div
class
=
"body"
>
<h1
class
=
"mod-title"
>
<span
class
=
"ico_log ico-<?php echo $type ?>"
></span>
</h1>
<div
class
=
"mod-ct"
>
<div
class
=
"order"
>
</div>
<div
class
=
"amount"
id=
"money"
>¥<?php
echo
$price
?></div>
<div
class
=
"qrcode-img-wrapper"
data-role=
"qrPayImgWrapper"
>
<div data-role=
"qrPayImg"
class
=
"qrcode-img-area"
>
<div
class
=
"ui-loading qrcode-loading"
data-role=
"qrPayImgLoading"
style=
"display: none;"
>加载中</div>
<div style=
"position: relative;display: inline-block;"
>
<img id='show_qrcode' alt=
"加载中..."
src=
"<?php echo $qr ?>"
width=
"210"
style=
"max-width:90%"
style=
"display: block;"
>
<img onclick=
"$('#use').hide()"
id=
"use"
src=
"<?php echo $codepay_path ?>/img/use_<?php echo $type ?>.png"
style=
"position: absolute;top: 50%;left: 50%;width:32px;height:32px;margin-left: -21px;margin-top: -21px"
>
</div>
</div>
</div>
<!-- 这里可以输入你想要的提示!-->
<div
class
=
"time-item"
id=
"msg"
>
<h1>二维码过期时间</h1>
<strong id=
"hour_show"
>0时</strong>
<strong id=
"minute_show"
>0分</strong>
<strong id=
"second_show"
>0秒</strong>
</div>
<div
class
=
"tip"
>
<div
class
=
"ico-scan"
></div>
<div
class
=
"tip-text"
>
<p>请使用<?php
echo
$typeName
?>扫一扫</p>
<p>扫描二维码完成支付</p>
<p><div id=
"kf"
></div></p>
</div>
</div>
<div
class
=
"detail"
id=
"orderDetail"
>
<dl
class
=
"detail-ct"
id=
"desc"
style=
"display: none;"
>
<dt>状态</dt>
<dd id=
"createTime"
>订单创建</dd>
</dl>
<a href=
"javascript:void(0)"
class
=
"arrow"
><i
class
=
"ico-arrow"
></i></a>
</div>
<div
class
=
"tip-text"
>
</div>
</div>
<div
class
=
"foot"
>
<div
class
=
"inner"
>
<p>手机用户可保存上方二维码到手机中</p>
<p>在<?php
echo
$typeName
?>扫一扫中选择“相册”即可</p>
</div>
</div>
</div>
<div
class
=
"copyRight"
>
</div>
<!--注意下面加载顺序 顺序错乱会影响业务-->
<script src=
"<?php echo $codepay_path ?>/js/jquery-1.10.2.min.js"
></script>
<!--[
if
lt IE 8]>
<script src=
"<?php echo $codepay_path ?>/js/json3.min.js"
></script><![
endif
]-->
<script>
var
user_data =<?php
echo
json_encode(
$user_data
);?>
</script>
<script src=
"<?php echo $codepay_path ?>/js/notify.js"
></script>
<script src=
"<?php echo $codepay_path ?>/js/codepay_util.js"
></script>
<?php
echo
$codepay_html
; ?>
<script src=
"<?php echo $codepay_path?>/js/toastr.min.js"
></script>
<script src=
"<?php echo $codepay_path?>/js/clipboard.min.js"
></script>
<script>
setTimeout(
function
() {
$('#
use
').hide()
}, user_data.logoShowTime || 2000);
var
clipboard =
new
Clipboard('.
copy
');
clipboard.on('success',
function
(e) {
toastr.success(
"复制成功,可扫码付款时候粘贴到金额栏付款"
);
});
clipboard.on('error',
function
(e) {
document.querySelector('.
copy
');
toastr.warning(
"复制失败,请记住下必须付款的金额 不能多不能少否则不能成功"
);
});
</script>
</body>
</html>