super_buy.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <?php
  2. namespace app\index;
  3. class super_buy extends Base
  4. {
  5. function index()
  6. {
  7. $ssid = SafeRequest("ssid", "get");
  8. $super_sign = db("super_sign")->where("id", $ssid)->find();
  9. if (!$super_sign) {
  10. exit(include_once IN_ROOT . "source/pack/error/404.php");
  11. }
  12. $item = db("item")->where("type=4")->order("id")->find();
  13. $link = SafeRequest("link", "get");
  14. if ($link) {
  15. setcookie("downlink", $link, time() + 3600);
  16. } elseif (isset($_COOKIE["downlink"])) {
  17. $link = $_COOKIE["downlink"];
  18. }
  19. $buylist = db("super_code")->where("udid='" . $super_sign["udid"] . "' and user_id=" . $super_sign["user_id"])->order("id desc")->select();
  20. ?> <!DOCTYPE html>
  21. <html lang="">
  22. <head lang="zh">
  23. <meta charset="UTF-8">
  24. <title>超级签下载码购买 -<?php echo IN_NAME;?></title>
  25. <meta charset="utf-8">
  26. <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  27. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
  28. <meta name="renderer" content="webkit">
  29. <meta name="keywords" content="<?php echo IN_KEYWORDS;?>">
  30. <meta property="og:url" content="https://<?php echo $_SERVER["HTTP_HOST"];?>">
  31. <meta property="og:title" content="<?php echo IN_NAME;?>">
  32. <meta name="description" content="<?php echo IN_DESCRIPTION;?>">
  33. <link rel="stylesheet" href="/static/index/css/base.css"/>
  34. <style>
  35. header {
  36. padding: 10px;
  37. background-color: #ffe8dd;
  38. border: 1px solid #ffd5be;
  39. font-weight: bold;
  40. color: #ff671c;
  41. line-height: 1.5;
  42. text-align:center;
  43. }
  44. header a{position:absolute;color: #333;display:block;font-weight:normal;}
  45. article {
  46. padding: 10px;font-size:12px;
  47. }
  48. .icon {
  49. background: url(/static/index/image/icon-main.png?20190126) no-repeat;
  50. display: inline-block;
  51. }
  52. .icon-checkbox {
  53. width: 28px;
  54. height: 28px;
  55. background-position: 0 -39px;
  56. }
  57. .price-pay{padding:10px;}
  58. .price-pay li{
  59. height: 44px;
  60. border: 1px solid #eee;
  61. justify-content: center;
  62. align-items: center;
  63. margin-right: 0;
  64. margin-bottom: 10px;
  65. border-radius: 3px;
  66. padding: 12px 20px 11px;
  67. position: relative;
  68. cursor: pointer;
  69. }
  70. .price-pay li .left {
  71. padding-right: .6rem;
  72. float: left;
  73. }
  74. .price-pay li .text1 {
  75. color: #666;
  76. }
  77. .price-pay li .text2 {
  78. color: #333;
  79. margin-top: 5px;
  80. font-weight: 600;
  81. }
  82. .price-pay .right {
  83. float: right;
  84. color: #157df1;
  85. font-size: 30px;
  86. padding-left: 50px;
  87. border-left: 1px solid #e5e5e5;
  88. }
  89. .price-pay .right span {
  90. color: #666;
  91. font-size: 14px;
  92. }
  93. .price-pay li .radio-checked {
  94. display: none;
  95. position: absolute;
  96. right: 0;
  97. bottom: 0;
  98. }
  99. .price-pay li.active .radio-checked {
  100. display: block;
  101. }
  102. .price-pay .active {
  103. border-color: #157df1;
  104. }
  105. .paytype{padding: 10px;}
  106. .paytype .list3 li{width: 40%; border: 1px solid #eee; justify-content: center; align-items: center; margin: 2%;float:left;padding:1%;position: relative;}
  107. .paytype .list3 li img{display: inline-block;}
  108. .paytype .list3 .active{border-color: #157df1;}
  109. .paytype li .radio-checked {
  110. display: none;
  111. position: absolute;
  112. right: 0;
  113. bottom: 0;
  114. }
  115. .paytype li.active .radio-checked {
  116. display: block;
  117. }
  118. .btn {
  119. display: block;
  120. background-color: #1B8DFA;
  121. width: 80%;
  122. height: 40px;
  123. line-height: 40px;
  124. margin: 0 auto;
  125. text-decoration: none;
  126. text-align: center;
  127. font-size: 16px;
  128. color: #fff;
  129. border-radius: 4px;
  130. }
  131. .buylog{margin-top:20px;padding:10px;}
  132. .buylog .tit{border-top:solid 1px #ccc;padding:5px 0;}
  133. .buylog ul{margin:10px 0;}
  134. .buylog li{color:#333;float:left;width:25%;}
  135. .buylog li.c1{width:10%;}
  136. .buylog li.c2{width:30%;}
  137. .buylog li.c2 a{color:#1B8DFA;}
  138. .buylog li.c3{width:20%;}
  139. .buylog li.c4{width:40%;}
  140. </style>
  141. <script charset="utf-8" src="/static/index/js/jquery.min.js"></script>
  142. <script src="/static/index/js/clipboard.min.js"></script>
  143. </head>
  144. <body>
  145. <header><a href="<?php echo $link;?>">< 返回下载</a> 超级签下载码购买</header>
  146. <article>
  147. <p>使用说明:一个下载码对应一个手机,验证使用后,其它手机不能再使用此下载码。</p>
  148. </article>
  149. <ul class="clearfix price-pay">
  150. <li class="clearfix active">
  151. <div class="left"><div class="text1">下载码</div> <div class="text2">1个</div></div> <div class="right"><?php echo $item["price"];?><span>元</span></div> <span class="radio-checked icon icon-checkbox"></span>
  152. </li>
  153. </ul>
  154. <div class="paytype">
  155. <div class="tit">选择支付方式</div>
  156. <ul class="clearfix list3" id="list3">
  157. <?php
  158. $IN_PAY = json_decode(IN_PAY, true);
  159. $pay_type = $IN_PAY[1];
  160. if (in_array(1, $IN_PAY)) {
  161. ?> <li class="clearfix active" data="1">
  162. <img src="/static/index/image/pay-1.jpg" alt="">
  163. <span class="radio-checked icon icon-checkbox"></span>
  164. </li>
  165. <?php
  166. }
  167. ?> <?php
  168. if (in_array(2, $IN_PAY)) {
  169. ?> <li class="clearfix" data="2">
  170. <img src="/static/index/image/pay-2.jpg" alt="">
  171. <span class="radio-checked icon icon-checkbox"></span>
  172. </li>
  173. <?php
  174. }
  175. ?>
  176. <?php
  177. if (in_array(5, $IN_PAY)) {
  178. ?> <li class="clearfix" data="5">
  179. <img src="/static/index/image/pay-5.jpg" alt="">
  180. <span class="radio-checked icon icon-checkbox"></span>
  181. </li>
  182. <?php
  183. }
  184. ?> <?php
  185. if (in_array(7, $IN_PAY)) {
  186. ?> <li class="clearfix" data="7">
  187. <img src="/static/index/image/pay-7.jpg" alt="">
  188. <span class="radio-checked icon icon-checkbox"></span>
  189. </li>
  190. <?php
  191. }
  192. ?> </ul>
  193. </div>
  194. <div class="pay-btn" style="margin-top:20px;"><a href="javascript:;" class="btn toPay">立即支付</a></div>
  195. <div class="buylog">
  196. <div class="tit">您的购买记录:</div>
  197. <ul class="clearfix">
  198. <li class="c1">序号</li><li class="c2">下载码</li><li class="c3">状态</li><li class="c4">购买时间</li>
  199. </ul>
  200. <?php
  201. foreach ($buylist as $k => $v) {
  202. $use_status = $v["use_time"] ? "已使用" : "未使用";
  203. if ($v["use_time"] && $v["cert_iss"]) {
  204. $cert_st = db("super_cert")->where("iss", $v["cert_iss"])->value("status");
  205. if (!$cert_st || $cert_st == -1) {
  206. $use_status = "已失效";
  207. }
  208. }
  209. ?><ul class="clearfix"><li class="c1"><?php echo $k + 1;?></li><li class="c2"><a class="copy" title="<?php echo $v["code"];?>"><?php echo $v["code"];?></a></li><li class="c3"><?php echo $use_status;?></li><li class="c4"><?php echo date("Y-m-d H:i", $v["create_time"]);?></li></ul><?php
  210. }
  211. ?> </div>
  212. <script>
  213. $(function () {
  214. $(".paytype ul").on("click", "li:not('.disabled')", function () {
  215. $(this).addClass("active").siblings().removeClass("active");
  216. });
  217. $(document).on('click', '.toPay', function () {
  218. var ssid = '<?php echo $ssid;?>';
  219. var discount_id = '<?php echo $item["id"];?>';
  220. pay_type = $(".paytype li.active").attr('data');
  221. if (!pay_type || pay_type == 'undefined') {
  222. alert('请选择支付渠道');
  223. return;
  224. }
  225. $(".pay-btn a:last").addClass("disabled");
  226. $(".pay-btn a:last").removeClass("toPay");
  227. $.ajax({
  228. async: false,
  229. type: "POST",
  230. url: '/index/ajax/super_buy',
  231. data: 'discount_id=' + discount_id + '&pay_type=' + pay_type + '&ssid=' + ssid,
  232. dataType: 'json',
  233. success: function (result) {
  234. $(".pay-btn a:last").removeClass("disabled");
  235. $(".pay-btn a:last").addClass("toPay");
  236. if (result.code != 200) {
  237. alert(result.msg);
  238. return;
  239. }
  240. form = $("<form target='_self'></form>");
  241. form.attr('action', '/index/super_buy/pay');
  242. form.attr('method', 'get');
  243. form.append($("<input type='hidden' name='trade_id' value='" + result.data.trade_id + "'/>"));
  244. form.append($("<input type='hidden' name='pay_type' value='" + result.data.pay_type + "' />"));
  245. form.append($("<input type='hidden' name='ssid' value='" + result.data.ssid + "'/>"));
  246. form.appendTo("body");
  247. form.submit();
  248. }
  249. });
  250. })
  251. var clipboard = new ClipboardJS('.copy', {
  252. text: function (trigger) {
  253. alert('复制成功');
  254. trigger.style.color = "red";
  255. return trigger.getAttribute('title');
  256. }
  257. });
  258. });
  259. </script>
  260. </body>
  261. </html>
  262. <?php
  263. }
  264. function pay()
  265. {
  266. $trade_id = SafeRequest("trade_id", "get");
  267. $pay_type = SafeRequest("pay_type", "get");
  268. $ssid = SafeRequest("ssid", "get");
  269. $payinfo = db("paylog")->where("pay_id", $trade_id)->find();
  270. $gourl = "/index/super_buy?ssid=" . $ssid;
  271. if (!$payinfo || !$pay_type || !in_array($pay_type, json_decode(IN_PAY, true))) {
  272. exit(include_once IN_ROOT . "source/pack/error/404.php");
  273. }
  274. $ssl = is_ssl() ? "https://" : "http://";
  275. if ($pay_type == "1") {
  276. include_once IN_ROOT . "source/pack/pay/alipay/alipay.class.php";
  277. $returnUrl = $ssl . $_SERVER["HTTP_HOST"] . IN_PATH . "index/super_buy?ssid=" . $ssid;
  278. $notifyUrl = $ssl . $_SERVER["HTTP_HOST"] . IN_PATH . "pay/index/alipay_notify";
  279. $outTradeNo = $payinfo["pay_id"];
  280. $payAmount = $payinfo["pay_money"];
  281. $orderName = $payinfo["pay_tag"];
  282. $signType = "MD5";
  283. $pid = IN_ALIPAYID;
  284. $privateKey = IN_ALIPAYKEY;
  285. $aliPay = new \AlipayService($pid, $returnUrl, $notifyUrl, $signType, $privateKey);
  286. $sHtml = $aliPay->doPay($payAmount, $outTradeNo, $orderName, $returnUrl, $notifyUrl, 1);
  287. echo $sHtml;
  288. exit;
  289. }
  290. if ($pay_type == "2") {
  291. define("IN_WXUID", $this->userid);
  292. include_once IN_ROOT . "source/pack/pay/weixin/WxPay.Api.php";
  293. include_once IN_ROOT . "source/pack/pay/weixin/WxPay.NativePay.php";
  294. $input = new \WxPayUnifiedOrder();
  295. $input->SetBody($payinfo["pay_tag"]);
  296. $input->SetOut_trade_no($payinfo["pay_id"]);
  297. $input->SetTotal_fee($payinfo["pay_money"] * 100);
  298. $input->SetTime_start(date("YmdHis"));
  299. $input->SetTime_expire(date("YmdHis", time() + 600));
  300. $input->SetNotify_url($ssl . $_SERVER["HTTP_HOST"] . IN_PATH . "pay/index/wxpay_notify");
  301. $input->SetTrade_type("NATIVE");
  302. $input->SetProduct_id($payinfo["in_id"]);
  303. $notify = new \NativePay();
  304. $result = $notify->GetPayUrl($input);
  305. if ($result["return_code"] == "FAIL") {
  306. $err = $result["return_msg"];
  307. exit(include_once IN_ROOT . "source/pack/error/404.php");
  308. } else {
  309. $code_url = $result["code_url"];
  310. }
  311. }
  312. if ($pay_type == "5") {
  313. include_once IN_ROOT . "source/pack/pay/f2fpay/alipay.class.php";
  314. $notifyUrl = $ssl . $_SERVER["HTTP_HOST"] . IN_PATH . "pay/index/f2fpay_notify";
  315. $orderName = $payinfo["pay_tag"];
  316. $config = ["appId" => IN_F2FPAYID, "signType" => IN_F2FPAY_STYPE, "privateKey" => IN_F2FPAY_MKEY, "publicKey" => IN_F2FPAY_AKEY, "notifyUrl" => $notifyUrl];
  317. $data = ["body" => $orderName, "subject" => $payinfo["pay_tag"], "out_trade_no" => $payinfo["pay_id"], "total_amount" => $payinfo["pay_money"]];
  318. $aliPay = new \AlipayService($config);
  319. $result = $aliPay->qrpay($data);
  320. if ($result["code"] != "10000") {
  321. $err = $result["msg"];
  322. exit(include_once IN_ROOT . "source/pack/error/404.php");
  323. } else {
  324. $code_url = $result["qr_code"];
  325. }
  326. }
  327. if ($pay_type == "7") {
  328. $api = "https://admin.zhanzhangfu.com/order/createOrder";
  329. $postDatas = array("price" => $payinfo["pay_money"], "name" => $payinfo["pay_tag"], "thirduid" => $payinfo["pay_id"], "remarks" => $payinfo["pay_tag"], "callbackurl" => $ssl . $_SERVER["HTTP_HOST"] . IN_PATH . "pay/index/zzpay_notify");
  330. $headers = array("Payment-Key:" . IN_ZZPAY_AppKey, "Payment-Secret:" . IN_ZZPAY_AppSecret);
  331. $ch = curl_init();
  332. curl_setopt($ch, CURLOPT_URL, $api);
  333. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  334. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  335. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  336. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  337. curl_setopt($ch, CURLOPT_POST, TRUE);
  338. curl_setopt($ch, CURLOPT_POSTFIELDS, $postDatas);
  339. $output = curl_exec($ch);
  340. $zzpaydata = json_decode($output, true);
  341. curl_close($ch);
  342. if ($zzpaydata["code"] != 10001) {
  343. $err = $zzpaydata["msg"];
  344. exit(include_once IN_ROOT . "source/pack/error/404.php");
  345. }
  346. }
  347. ?> <!DOCTYPE html>
  348. <html lang="">
  349. <head lang="zh">
  350. <meta charset="UTF-8">
  351. <title>超级签下载码购买 -<?php echo IN_NAME;?></title>
  352. <meta charset="utf-8">
  353. <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  354. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
  355. <meta name="renderer" content="webkit">
  356. <meta name="keywords" content="<?php echo IN_KEYWORDS;?>">
  357. <meta property="og:url" content="https://<?php echo $_SERVER["HTTP_HOST"];?>">
  358. <meta property="og:title" content="<?php echo IN_NAME;?>">
  359. <meta name="description" content="<?php echo IN_DESCRIPTION;?>">
  360. <link rel="stylesheet" href="/static/index/css/base.css"/>
  361. <style>
  362. header {
  363. padding: 10px;
  364. background-color: #ffe8dd;
  365. border: 1px solid #ffd5be;
  366. font-weight: bold;
  367. color: #ff671c;
  368. line-height: 1.5;
  369. text-align:center;
  370. }
  371. header a{position:absolute;color: #333;display:block;font-weight:normal;}
  372. article {
  373. padding: 10px 15px;font-size:12px;
  374. }
  375. .qrcode{
  376. border-color: #157df1;
  377. margin: 20px;
  378. border-radius: 3px;
  379. padding: 12px 20px 11px;
  380. text-align:center;
  381. }
  382. .qrcode img{max-width:100%;}
  383. </style>
  384. <script charset="utf-8" src="/static/index/js/jquery.min.js"></script>
  385. </head>
  386. <body>
  387. <header><a href="javascript:history.back();">< 返回</a>超级签下载码购买</header>
  388. <article>
  389. <p>支付说明:请保存支付二维码扫手机,然后扫码选择相册中二维码进行支付,支付完成后,会自动跳转到购买记录页面。</p>
  390. </article>
  391. <?php
  392. if ($pay_type == 2 || $pay_type == 5) {
  393. ?> <div class="qrcode">
  394. <img src="/qrcode?link=<?php echo $code_url;?>">
  395. <p> * 请您尽快完成支付 </p>
  396. </div>
  397. <?php
  398. }
  399. if ($pay_type == 7 && $zzpaydata) {
  400. ?> <link rel="stylesheet" type="text/css" href="/static/zzpay/css/onlinepay.css">
  401. <script>
  402. var timestr = "2020-09-29 14:05:20";
  403. var serverTime = (new Date(timestr.replace(/-/g, '/'))).getTime();//服务器初始时间
  404. var diffTime = (new Date()).getTime() - serverTime;//服务器校对时间差秒数
  405. diffTime = diffTime / 1000;
  406. </script>
  407. <div class="mod-ct">
  408. <h1 class="mod-title">
  409. <!--支付宝支付图标-->
  410. <p style="color: rgb(51, 51, 51); font-size: 12px; margin-top: 10px; display: none;" class="n-wx-zfb">
  411. 请先截屏,使用支付宝"扫一扫"识别相册图片支付</p>
  412. <span class="ico_log ico-4"></span><span class="ico_log ico-3"></span>
  413. </h1>
  414. <div class="order"></div>
  415. <div class="amount" id="money"><span class="amount2"><?php echo $zzpaydata["price"];?></span></span></span></div>
  416. <div class="paybtn" style="display: none;"><a href="" id="alipaybtn" class="btn btn-primary" target="_blank">启动支付宝App支付</a>
  417. </div>
  418. <div class="qrcode-img-wrapper" data-role="qrPayImgWrapper">
  419. <div data-role="qrPayImg" class="qrcode-img-area">
  420. <div class="ui-loading qrcode-loading" data-role="qrPayImgLoading" style="display: none;"></div>
  421. <div style="position: relative;display: inline-block;">
  422. <!--付款码记得替换为自己的-->
  423. <img id="imgCode2" src="<?php echo $zzpaydata["zfbcode"];?>">
  424. <img id="imgCode3" src="<?php echo $zzpaydata["wxcode"];?>">
  425. <!--支付宝图标/微信图标-->
  426. <input name="istype" id="istype" type="hidden" value="1">
  427. <div id="qrcode"></div>
  428. <img src="" style="display: none" id="qrLost">
  429. <canvas id="imgCanvas" width="310" height="270" style="display: none;"></canvas>
  430. <div class="timeOut" style="display: none">过期时间<span id="timeOut">2020-09-29 14:11:20</span></div>
  431. <input type="hidden" id="now_time" value="2020-09-29 14:05:20">
  432. </div>
  433. </div>
  434. </div>
  435. <div class="time-item" style="padding-top: 10px">
  436. <div class="time-item" id="msg">
  437. <h1 class="overtime">订单名称:<span><?php echo $zzpaydata["name"];?></span></h1>
  438. </div>
  439. <div class="time-item"><h1>订单号:<span><?php echo $zzpaydata["orderId"];?></span></h1>
  440. <input type="hidden" value="<?php echo $zzpaydata["orderId"];?>" id="orderId"></div>
  441. <strong id="hour_show"><s id="h"></s>订单支付有效期</strong>
  442. <strong id="minute_show"><s></s></strong>
  443. <strong id="second_show"><s></s></strong>
  444. <div class="time-item"></div>
  445. <strong class='resultMsg'><s></s>20秒后自动获取支付结果</strong>
  446. </div>
  447. <div class="tip">
  448. <div class="ico-scan"></div>
  449. <div class="tip-text">
  450. <!--支付宝支付提示/微信支付提示-->
  451. <p id="showtext">打开支付宝或微信[扫一扫]</p>
  452. </div>
  453. </div>
  454. <!--ie判断版本-->
  455. <!--[if IE 8]>
  456. <div class="tip-text" style="color:#ff0000">您的浏览器版本较低,请升级后再试!</div>
  457. <![endif]-->
  458. <!--[if lt IE 8]>
  459. <div class="tip-text" style="color:#ff0000">您的浏览器版本较低,请升级后再试!</div>
  460. <![endif]-->
  461. </div>
  462. <script type="text/javascript" src="/static/zzpay/js/onlinepay.js"></script>
  463. <?php
  464. }
  465. ?> <script>
  466. $(document).ready(function () {
  467. window.setInterval(function () {
  468. getPayStatus();
  469. }, 2000);
  470. });
  471. function getPayStatus() {
  472. $.getJSON('/index/tradeStatus?id=<?php echo $trade_id;?>', function (data) {
  473. if (data.code == 200) {
  474. alert('支付成功!');
  475. window.location.href = '<?php echo $gourl;?>';
  476. }
  477. });
  478. }
  479. </script>
  480. </body>
  481. </html>
  482. <?php
  483. }
  484. }