Jubaopay_payment.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维p2p借贷系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. /*
  10. // 测试商户编号
  11. partner_id = '14061642390911131749';
  12. */
  13. $payment_lang = array(
  14. 'name'=>'聚宝付(WAP支付)',
  15. 'partner_id' => '商户号',
  16. );
  17. $config = array(
  18. 'partner_id' => array(
  19. 'INPUT_TYPE' => '0',
  20. ),
  21. );
  22. /* 模块的基本信息 */
  23. if (isset($read_modules) && $read_modules == true) {
  24. $module['class_name'] = 'Jubaopay';
  25. /* 名称 */
  26. $module['name'] = $payment_lang['name'];
  27. /* 支付方式:1:在线支付;0:线下支付 2:仅wap支付 3:仅app支付 4:兼容wap和app*/
  28. $module['online_pay'] = '4';
  29. /* 配送 */
  30. $module['config'] = $config;
  31. $module['lang'] = $payment_lang;
  32. $module['reg_url'] = '';
  33. return $module;
  34. }
  35. require_once APP_ROOT_PATH . 'system/libs/payment.php';
  36. class Jubaopay_payment implements payment
  37. {
  38. public function get_payment_code($payment_notice_id)
  39. {
  40. $pay = array();
  41. $pay['is_wap'] = 1;//
  42. $pay['class_name'] = "Jubaopay";
  43. $pay['url'] =SITE_DOMAIN.APP_ROOT.'/mapi/index.php?ctl=pay&act=get_display_code&pay_code=Jubaopay&notice_id='.$payment_notice_id;
  44. $pay['sdk_code'] = array("pay_sdk_type"=>"yjwap","config"=>
  45. array(
  46. "url"=>SITE_DOMAIN.APP_ROOT.'/mapi/index.php?ctl=pay&act=get_display_code&pay_code=Jubaopay&notice_id='.$payment_notice_id,
  47. "is_wap"=>1
  48. )
  49. );
  50. return $pay;
  51. }
  52. public function notify($request)
  53. {
  54. $payment = $GLOBALS['db']->getRow("select id,config from " . DB_PREFIX . "payment where class_name='Jubaopay'");
  55. $payment['config'] = unserialize($payment['config']);
  56. require_once APP_ROOT_PATH . "system/payment/Jubaopay/jubaopay.php";
  57. $jubaopay=new jubaopay(APP_ROOT_PATH . "system/payment/Jubaopay/jubaopay.ini");
  58. $message=$request["message"];
  59. $signature=$request["signature"];
  60. $jubaopay->decrypt($message);
  61. // 校验签名,然后进行业务处理
  62. $result=$jubaopay->verify($signature);
  63. if($result==1) {
  64. $payment_notice_sn = $jubaopay->getEncrypt("payid");
  65. $outer_notice_sn = $jubaopay->getEncrypt("orderNo");
  66. $payment_notice = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment_notice where notice_sn = '" . $payment_notice_sn . "'");
  67. require_once APP_ROOT_PATH . "system/libs/cart.php";
  68. $rs = payment_paid($payment_notice['notice_sn'],$outer_notice_sn);
  69. if($rs['status']==1){
  70. echo "success"; // 像服务返回 "success";
  71. } else {
  72. echo "pay failed"; // 像服务返回 "success"
  73. }
  74. } else {
  75. echo "verify failed";;
  76. }
  77. }
  78. public function response($request)
  79. {
  80. $payment = $GLOBALS['db']->getRow("select id,config from " . DB_PREFIX . "payment where class_name='Jubaopay'");
  81. $payment['config'] = unserialize($payment['config']);
  82. require_once APP_ROOT_PATH . "system/payment/Jubaopay/jubaopay.php";
  83. $jubaopay=new jubaopay(APP_ROOT_PATH . "system/payment/Jubaopay/jubaopay.ini");
  84. $message=$request["message"];
  85. $signature=$request["signature"];
  86. $jubaopay->decrypt($message);
  87. // 校验签名,然后进行业务处理
  88. $result=$jubaopay->verify($signature);
  89. if($result == 1) {
  90. $payment_notice_sn = $jubaopay->getEncrypt("payid");
  91. $outer_notice_sn = $jubaopay->getEncrypt("orderNo");
  92. $payment_notice = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment_notice where notice_sn = '" . $payment_notice_sn . "'");
  93. require_once APP_ROOT_PATH . "system/libs/cart.php";
  94. $rs = payment_paid($payment_notice['notice_sn'],$outer_notice_sn);
  95. if($rs['status']==1){
  96. echo '<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=0,minimum-scale=0.5"><title></title><script>function close_page(){try{App.close_page();}catch(e){alert("SDK调用失败");}}</script></head><body><div style="width:120px;height:40px;line-height:40px;font-size:14px;text-align:center;background:#ff4d7f;color:#fff;margin:20px auto;border-radius:5px;" onclick="close_page();">支付成功!关闭当前页面</div></body></html>';
  97. } else {
  98. echo '<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=0,minimum-scale=0.5"><title></title><script>function close_page(){try{App.close_page();}catch(e){alert("SDK调用失败");}}</script></head><body><div style="width:120px;height:40px;line-height:40px;font-size:14px;text-align:center;background:#ff4d7f;color:#fff;margin:20px auto;border-radius:5px;" onclick="close_page();">支付成功,回调失败!关闭当前页面</div></body></html>';
  99. }
  100. } else {
  101. echo '<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=0,minimum-scale=0.5"><title></title><script>function close_page(){try{App.close_page();}catch(e){alert("SDK调用失败");}}</script></head><body><div style="width:120px;height:40px;line-height:40px;font-size:14px;text-align:center;background:#ff4d7f;color:#fff;margin:20px auto;border-radius:5px;" onclick="close_page();">支付成功,回调失败!关闭当前页面</div></body></html>';
  102. }
  103. }
  104. public function get_display_code()
  105. {
  106. }
  107. public function display_code($payment_notice_id)
  108. {
  109. if($payment_notice_id){
  110. $payment_notice = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."payment_notice where id = ".$payment_notice_id);
  111. $money = round($payment_notice['money'],2);
  112. $payment_info = $GLOBALS['db']->getRow("select id,config,logo from ".DB_PREFIX."payment where id=".intval($payment_notice['payment_id']));
  113. $payment_info['config'] = unserialize($payment_info['config']);
  114. $m_config = load_auto_cache("m_config");
  115. $title_name = $m_config['ticket_name'];
  116. if($title_name=='')$title_name = '虚拟印币';
  117. $subject = msubstr($title_name,0,40);
  118. require_once APP_ROOT_PATH . "system/payment/Jubaopay/jubaopay.php";
  119. $jubaopay=new jubaopay(APP_ROOT_PATH . "system/payment/Jubaopay/jubaopay.ini");
  120. $payid=$payment_notice['notice_sn'];
  121. $partnerid=$payment_info['config']['partner_id'];
  122. $amount=$money;
  123. $payerName=$payment_notice['user_id'];
  124. $remark=$subject;
  125. $returnURL= 'http://live.huangjiaxiuchang.com/callback/payment/jubaopay_response.php'; // 可在商户后台设置
  126. $callBackURL= 'http://live.huangjiaxiuchang.com/callback/payment/jubaopay_notify.php'; // 可在商户后台设置
  127. $goodsName=$subject;
  128. //////////////////////////////////////////////////////////////////////////////////////////////////
  129. //商户利用支付订单(payid)和商户号(mobile)进行对账查询
  130. $jubaopay->setEncrypt("payid", $payid);
  131. $jubaopay->setEncrypt("partnerid", $partnerid);
  132. $jubaopay->setEncrypt("amount", $amount);
  133. $jubaopay->setEncrypt("payerName", $payerName);
  134. $jubaopay->setEncrypt("remark", $remark);
  135. $jubaopay->setEncrypt("returnURL", $returnURL);
  136. $jubaopay->setEncrypt("callBackURL", $callBackURL);
  137. $jubaopay->setEncrypt("goodsName", $goodsName);
  138. $jubaopay->interpret();
  139. $message=$jubaopay->message;
  140. $signature=$jubaopay->signature;
  141. $payLinks = '<form method="post" action="https://mapi.jubaopay.com/apiwapsyt.htm" id="payForm">';
  142. $payLinks .= '<input type="hidden" name="message" id="message" value="' . $message . '" />';
  143. $payLinks .= '<input type="hidden" name="signature" id="signature" value="' . $signature. '"/>';
  144. $payLinks .= '</form>';
  145. $payLinks .= '<script type="text/javascript">document.getElementById("payForm").submit();</script>';
  146. return $payLinks;
  147. }
  148. else
  149. {
  150. return '';
  151. }
  152. }
  153. }