Wwxjspay_payment.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | EaseTHINK 易想团购系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2010 http://www.easethink.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. $payment_lang = array(
  8. 'name' => '微信WAP(充值/提现)',
  9. 'appid' => '微信公众号ID',
  10. 'appsecret'=>'微信公众号SECRT',
  11. 'mchid' => '微信支付MCHID',
  12. // 'partnerid' => '商户ID',
  13. //'partnerkey' => '商户key',
  14. 'key' => '商户支付密钥Key/api秘钥',
  15. 'sslcert'=>'apiclient_cert证书路径',
  16. 'sslkey'=>'apiclient_key证书路径',
  17. 'type'=>'类型(V3或V4)',
  18. );
  19. $config = array(
  20. 'appid'=>array(
  21. 'INPUT_TYPE'=>'0',
  22. ),//微信公众号ID
  23. 'appsecret' => array(
  24. 'INPUT_TYPE' => '0',
  25. ), //微信公众号SECRT
  26. 'mchid' => array(
  27. 'INPUT_TYPE' => '0'
  28. ), //微信支付MCHID
  29. // 'partnerid' => array(
  30. // 'INPUT_TYPE' => '0'
  31. // ), //商户ID
  32. // 'partnerkey' => array(
  33. // 'INPUT_TYPE' => '0'
  34. // ), //商户key
  35. 'key' => array(
  36. 'INPUT_TYPE' => '0',
  37. ), //商户支付密钥Key
  38. 'sslcert' => array(
  39. 'INPUT_TYPE' => '0',
  40. ), //apiclient_cert证书路径
  41. 'sslkey' => array(
  42. 'INPUT_TYPE' => '0',
  43. ), //apiclient_key证书路径
  44. 'type' => array(
  45. 'INPUT_TYPE' => '0',
  46. ), //类型
  47. );
  48. /* 模块的基本信息 */
  49. if (isset($read_modules) && $read_modules == true)
  50. {
  51. $module['class_name'] = 'Wwxjspay';
  52. /* 名称 */
  53. $module['name'] = $payment_lang['name'];
  54. /* 支付方式:1:在线支付;0:线下支付;2:手机wap;3:手机sdk */
  55. $module['online_pay'] = '2';
  56. /* 配送 */
  57. $module['config'] = $config;
  58. $module['lang'] = $payment_lang;
  59. $module['reg_url'] = '';
  60. return $module;
  61. }
  62. // 支付宝手机支付模型
  63. require_once(APP_ROOT_PATH.'system/libs/payment.php');
  64. class Wwxjspay_payment implements payment {
  65. public function get_payment_code($payment_notice_id)
  66. {
  67. $payment_notice = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."payment_notice where id = ".$payment_notice_id);
  68. //log_result("==payment_notice==");
  69. //log_result($payment_notice);
  70. //$order_sn = $GLOBALS['db']->getOne("select order_sn from ".DB_PREFIX."deal_order where id = ".$payment_notice['order_id']);
  71. $money = round($payment_notice['money'],2);
  72. $payment_info = $GLOBALS['db']->getRow("select id,config,logo from ".DB_PREFIX."payment where id=".intval($payment_notice['payment_id']));
  73. $payment_info['config'] = unserialize($payment_info['config']);
  74. //log_result("==payment_info==");
  75. //log_result($payment_info);
  76. $this->init_define($payment_info);
  77. /*$sql = "select name ".
  78. "from ".DB_PREFIX."deal_order_item ".
  79. "where order_id =". intval($payment_notice['order_id']);
  80. $title_name = $GLOBALS['db']->getOne($sql);*/
  81. $m_config = load_auto_cache("m_config");
  82. $title_name = $m_config['ticket_name'];
  83. if($title_name=='')
  84. $title_name = '虚拟印币';
  85. if(empty($title_name))
  86. {
  87. $title_name = "充值".round($payment_notice['money'],2)."元";
  88. }
  89. $pay['pay_info'] = $title_name;
  90. $pay['payment_name'] = "微信支付";
  91. $pay['pay_money'] = $money;
  92. $pay['pay_id'] = $payment_notice['id'];
  93. $pay['class_name'] = "Wxxjspay";
  94. //$subject = msubstr($title_name,0,40);
  95. $subject = $title_name;
  96. //$data_return_url = get_domain().APP_ROOT.'/../payment.php?act=return&class_name=Malipay';
  97. //$notify_url = get_domain().APP_ROOT.'/../shop.php?ctl=payment&act=response&class_name=Malipay';
  98. $data_notify_url = 'http://live.huangjiaxiuchang.com/callback/payment/wwxjspay_notify.php';
  99. require_once(APP_ROOT_PATH.'system/payment/Wxapp/WxPay.Api.php');
  100. require_once(APP_ROOT_PATH.'system/payment/Wxapp/WxPay.Notify.php');
  101. require_once(APP_ROOT_PATH.'system/payment/Wxapp/WxPay.Data.php');
  102. require_once(APP_ROOT_PATH.'system/payment/Wxapp/WxPay.JsApiPay.php');
  103. //获取用户openid
  104. $tools = new JsApiPay();
  105. $openId = $tools->GetOpenid();
  106. //统一下单
  107. $input = new WxPayUnifiedOrder();
  108. $input->SetAppid($payment_info['config']['appid']);
  109. $input->SetMch_id($payment_info['config']['mchid']);
  110. $input->SetBody($payment_notice['notice_sn']);
  111. $input->SetOut_trade_no($payment_notice['notice_sn']);
  112. $input->SetTotal_fee($money * 100);
  113. //$input->SetTime_start(to_date(get_gmtime(),"YmdHis"));
  114. //$input->SetTime_expire(date("YmdHis", time() + 600));
  115. //$input->SetGoods_tag($title_name);
  116. $input->SetNotify_url($data_notify_url);
  117. $input->SetTrade_type("JSAPI");
  118. $input->SetOpenid($openId);
  119. $result = WxPayApi::unifiedOrder($input);
  120. $jsApiParameters = $tools->GetJsApiParameters($result);
  121. //微信定时日志 7天以后删除
  122. //log_result_wx_pay_log("==jsApiParameters==");
  123. //log_result_wx_pay_log($jsApiParameters);
  124. return $jsApiParameters;
  125. }
  126. function init_define($payment){
  127. define('WXAPP_APPID',$payment['config']['appid']);
  128. define('WXAPP_MCHID',$payment['config']['mchid']);
  129. define('WXAPP_KEY',$payment['config']['key']);
  130. define('WXAPP_APPSECRET',$payment['config']['appsecret']);
  131. define('WXAPP_SSLCERT_PATH','');
  132. define('WXAPP_SSLKEY_PATH','');
  133. define('WXAPP_CURL_PROXY_HOST',"0.0.0.0");
  134. define('WXAPP_CURL_PROXY_PORT',0);
  135. define('WXAPP_REPORT_LEVENL',1);
  136. }
  137. public function notify($request)
  138. {
  139. //log_result("==notify_request==");
  140. //log_result($request);
  141. $payment = $GLOBALS['db']->getRow("select id,config from ".DB_PREFIX."payment where class_name='Wwxjspay'");
  142. $payment['config'] = unserialize($payment['config']);
  143. $this->init_define($payment);
  144. //print_r($payment['config']);
  145. //log_result("==payment==");
  146. //log_result($payment);
  147. require_once(APP_ROOT_PATH.'system/payment/Wxapp/WxPay.Api.php');
  148. require_once(APP_ROOT_PATH.'system/payment/Wxapp/WxPay.Notify.php');
  149. require_once(APP_ROOT_PATH.'system/payment/Wxapp/WxPay.Data.php');
  150. try {
  151. $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
  152. $result = WxPayResults::Init($xml);
  153. $verify = 1;
  154. } catch (WxPayException $e){
  155. //微信定时日志 7天以后删除
  156. log_result_wx_pay_log("提现失败result");
  157. log_result_wx_pay_log($e->errorMessage());
  158. $msg = $e->errorMessage();
  159. //return false;
  160. $verify = 0;
  161. }
  162. if ($verify == 1)
  163. {
  164. //微信定时日志 7天以后删除
  165. //log_result_wx_pay_log("result");
  166. //log_result_wx_pay_log($result);
  167. if ($result['return_code'] == 'SUCCESS'){
  168. $payment_notice_sn = $result['out_trade_no'];
  169. $outer_notice_sn = $result['transaction_id'];
  170. $payment_notice = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."payment_notice where notice_sn = '".$payment_notice_sn."'");
  171. //log_result("==payment_notice==");
  172. //log_result($payment_notice);
  173. //$order_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."deal_order where id = ".$payment_notice['order_id']);
  174. require_once APP_ROOT_PATH."system/libs/cart.php";
  175. $rs = payment_paid($payment_notice['notice_sn'],$outer_notice_sn);
  176. if ($rs)
  177. {
  178. //file_put_contents(APP_ROOT_PATH."/alipaylog/1.txt","");
  179. //$GLOBALS['db']->query("update ".DB_PREFIX."payment_notice set outer_notice_sn = '".$outer_notice_sn."' where id = ".$payment_notice['id']);
  180. //order_paid($payment_notice['order_id']);
  181. echo "success";
  182. }else{
  183. //file_put_contents(APP_ROOT_PATH."/alipaylog/2.txt","");
  184. echo "success";
  185. }
  186. }else{
  187. //file_put_contents(APP_ROOT_PATH."/alipaylog/3.txt","");
  188. echo "fail";
  189. }
  190. }
  191. else
  192. {
  193. //file_put_contents(APP_ROOT_PATH."/alipaylog/4.txt","");
  194. echo "fail";
  195. }
  196. exit;
  197. }
  198. //响应通知
  199. function response($request)
  200. {}
  201. //获取接口的显示
  202. function get_display_code()
  203. {
  204. return "微信支付";
  205. }
  206. }
  207. ?>