Pah_payment.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. $payment_lang = array(
  10. 'name' => '平安汇支付宝扫码支付',
  11. 'MERNO' => '商户号',
  12. 'TERMNO'=> '终端号',
  13. 'RSA'=> '微信签名密钥',
  14. );
  15. $config = array(
  16. 'MERNO' => array(
  17. 'INPUT_TYPE' => '0',
  18. ), //商户号
  19. 'TERMNO' => array(
  20. 'INPUT_TYPE' => '0',
  21. ), //终端号
  22. 'RSA' => array(
  23. 'INPUT_TYPE' => '0',
  24. ), //微信签名密钥
  25. );
  26. /* 模块的基本信息 */
  27. if (isset($read_modules) && $read_modules == true)
  28. {
  29. $module['class_name'] = 'Pah';
  30. /* 名称 */
  31. $module['name'] = $payment_lang['name'];
  32. /* 支付方式:1:在线支付;0:线下支付 2:仅wap支付 3:仅app支付 4:兼容wap和app*/
  33. $module['online_pay'] = '4';
  34. /* 配送 */
  35. $module['config'] = $config;
  36. $module['lang'] = $payment_lang;
  37. $module['reg_url'] = '';
  38. return $module;
  39. }
  40. // 平安汇支付模型
  41. require_once(APP_ROOT_PATH.'system/libs/payment.php');
  42. class Pah_payment implements payment {
  43. public function get_payment_code($payment_notice_id)
  44. {
  45. $pay = array();
  46. $pay['is_wap'] = 1;//
  47. $pay['class_name'] = "Pah";
  48. $pay['url'] =SITE_DOMAIN.APP_ROOT.'/mapi/index.php?ctl=pay&act=get_display_code&pay_code=Pah&notice_id='.$payment_notice_id;
  49. $pay['sdk_code'] = array("pay_sdk_type"=>"yjwap","config"=>
  50. array(
  51. "url"=>SITE_DOMAIN.APP_ROOT.'/mapi/index.php?ctl=pay&act=get_display_code&pay_code=Pah&notice_id='.$payment_notice_id,
  52. "is_wap"=>1
  53. )
  54. );
  55. return $pay;
  56. }
  57. public function response($request)
  58. {}
  59. public function notify($request)
  60. {
  61. }
  62. function get_display_code(){
  63. }
  64. public function display_code($payment_notice_id)
  65. {
  66. if($payment_notice_id){
  67. $payment_notice = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."payment_notice where id = ".$payment_notice_id);
  68. $money = round($payment_notice['money'],2);
  69. $payment_info = $GLOBALS['db']->getRow("select id,config,logo from ".DB_PREFIX."payment where id=".intval($payment_notice['payment_id']));
  70. $payment_info['config'] = unserialize($payment_info['config']);
  71. $m_config = load_auto_cache("m_config");
  72. $title_name = $m_config['ticket_name'];
  73. if($title_name=='')$title_name = '虚拟印币';
  74. $subject = msubstr($title_name,0,40);
  75. $body=array();
  76. $body['MERNO']=$payment_info['config']['MERNO'];
  77. $body['TERMNO']=$payment_info['config']['TERMNO'];
  78. $body['AMT']=intval($money*100);
  79. $body['TYPE']="1";
  80. $params=array();
  81. $params['CommandID']=2318;
  82. $params['MsgID']=NOW_TIME;
  83. $params['NodeType']=0;
  84. $params['NodeID']='app';
  85. $params['Version']='1.2.0';
  86. $params['Body']=$body;
  87. $params['Sign']=$this->MakeSign($params['Body'], $payment_info['config']['RSA']);
  88. //$url="http://123.58.32.141:20035/mpay/services";//测试地址
  89. //$url="https://172.19.0.22:1380/mpos/services/";
  90. //$url="https://www.lianyinggufen.com/mpos/services/";
  91. $url="https://www.lianyinggufen.com/mpay/services";
  92. try {
  93. // 执行HTTP POST请求
  94. $ch = curl_init(); // 初始化curl
  95. curl_setopt($ch, CURLOPT_URL, $url); // 服务地址
  96. curl_setopt($ch, CURLOPT_HEADER, false); // 设置header
  97. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 要求结果为字符串且输出到屏幕上
  98. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); // POST请求方式
  99. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
  100. /*$ch = curl_init(); // 初始化curl
  101. curl_setopt($ch, CURLOPT_URL, $url); // 服务地址
  102. curl_setopt($ch, CURLOPT_HEADER, false); // 设置header
  103. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 要求结果为字符串且输出到屏幕上
  104. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  105. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  106. curl_setopt($ch, CURLOPT_POST, true);
  107. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));*/
  108. /*$ch = curl_init();
  109. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // 跳过证书检查
  110. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在
  111. curl_setopt($ch, CURLOPT_URL, $url);
  112. curl_setopt($ch, CURLOPT_HTTPHEADER, json_encode($params));
  113. curl_setopt($ch, CURLOPT_POST, true);
  114. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
  115. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);*/
  116. /*fanwe_require(APP_ROOT_PATH .'mapi/lib/core/transport.php');
  117. $trans = new transport();
  118. $req = $trans->request($url,$params,'POST');
  119. var_dump($req);exit(); */
  120. $data = curl_exec($ch); // 运行curl
  121. $data=json_decode($data,1);
  122. if(empty($data))
  123. {
  124. $data = curl_error($ch);
  125. }
  126. curl_close($ch);
  127. if ($data['RetCode']==0) {
  128. $body2=$data['Body'];
  129. //二阶段处理 二维码正扫
  130. $body['PREORDERID']=$data['Body']['PREORDERID'];
  131. $params=array();
  132. $params['CommandID']=2308;
  133. $params['MsgID']=NOW_TIME;
  134. $params['NodeType']=0;
  135. $params['NodeID']='app';
  136. $params['Version']='1.2.0';
  137. $params['Body']=$body;
  138. $params['Sign']=$this->MakeSign($params['Body'], $payment_info['config']['RSA']);
  139. //var_dump(json_encode($params));
  140. $ch = curl_init(); // 初始化curl
  141. curl_setopt($ch, CURLOPT_URL, $url); // 服务地址
  142. curl_setopt($ch, CURLOPT_HEADER, false); // 设置header
  143. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 要求结果为字符串且输出到屏幕上
  144. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); // POST请求方式
  145. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
  146. $data2 = curl_exec($ch); // 运行curl
  147. $data2=json_decode($data2,1);
  148. if(empty($data2))
  149. {
  150. $data2 = curl_error($ch);
  151. }
  152. curl_close($ch);
  153. if ($data2['RetCode']==0) {
  154. //三阶段处理 生成付款链接
  155. $outer_notice_sn=$data2['Body']['ORDERNO'];
  156. $sql = "update ".DB_PREFIX."payment_notice set outer_notice_sn = ".$outer_notice_sn." where id =".$payment_notice_id;
  157. $GLOBALS['db']->query($sql);
  158. $CODE_URL=$data2['Body']['CODE_URL'];
  159. $invite_image_dir =APP_ROOT_PATH."public/pay_image";
  160. if (!is_dir($invite_image_dir)) {
  161. @mkdir($invite_image_dir, 0777);
  162. }
  163. $url=$CODE_URL;
  164. $path_dir = "/public/pay_image/pay_qrcode_".$payment_notice_id.".png";
  165. $path_logo_dir = "/public/pay_image/pay_qrcode_".$payment_notice_id.".png";
  166. $qrcode_dir = APP_ROOT_PATH.$path_dir;
  167. $qrcode_dir_logo = APP_ROOT_PATH.$path_logo_dir;
  168. if(!is_file($qrcode_dir)||!is_file($qrcode_dir_logo)){
  169. get_qrcode_png($url,$qrcode_dir,$qrcode_dir_logo);
  170. }
  171. header('Location:'.SITE_DOMAIN.$path_logo_dir);
  172. /*$payLinks ='<div class="weixin-container">';
  173. $payLinks .='<div class="qrcode-container">';
  174. $payLinks .='<div class="title">微信支付</div>';
  175. $payLinks .='<div class="qrcode">';
  176. $payLinks .='<div class="qrcode-img">';
  177. $payLinks .='<div class="" id="weixin_qrcode" rel="{'.$CODE_URL.'}"></div>';
  178. $payLinks .='</div>';
  179. $payLinks .='<div class="warning"></div>';
  180. $payLinks .='</div>';
  181. $payLinks .='<div class="tip">';
  182. $payLinks .='<i class="icon"></i>';
  183. $payLinks .='请使用微信扫一扫<br>';
  184. $payLinks .='扫描二维码支付';
  185. $payLinks .='</div>';
  186. $payLinks .='</div>';
  187. $payLinks .='<div class="mobile">';
  188. $payLinks .='<div class="img"></div>';
  189. $payLinks .='</div>';
  190. $payLinks .='</div>';
  191. return $payLinks;*/
  192. }else{
  193. return $data2['ErrorMsg'];
  194. }
  195. }else{
  196. return $data['ErrorMsg'];
  197. }
  198. }catch (Exception $e) {
  199. }
  200. exit();
  201. }
  202. else
  203. {
  204. return '';
  205. }
  206. }
  207. /**
  208. * 生成签名
  209. * @return 签名,
  210. */
  211. function MakeSign($values,$key)
  212. {
  213. ksort($values);
  214. //$string = $this->ToUrlParams($values);
  215. //签名步骤二:在string后加入KEY
  216. //$string = $string . "&key=".$key;
  217. $string = json_encode($values);
  218. $string = $string . '&key=' . $key;
  219. $string = md5($string);
  220. //签名步骤四:所有字符转为大写
  221. $result = strtoupper($string);
  222. return $result;
  223. }
  224. function ToUrlParams($urlObj)
  225. {
  226. $buff = "";
  227. foreach ($urlObj as $k => $v)
  228. {
  229. $buff .= $k . "=" . $v . "&";
  230. }
  231. $buff = trim($buff, "&");
  232. return $buff;
  233. }
  234. }
  235. ?>