wxpay_h5.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. class wxpay_h5
  3. {
  4. const DEBUG = 0;
  5. protected $config;
  6. public function __construct($payment_info = array())
  7. {
  8. define('WXN_APPID', $payment_info['payment_config']['wx_appid']);
  9. define('WXN_APPSECRET', $payment_info['payment_config']['wx_appsecret']);
  10. define('WXN_MCHID', $payment_info['payment_config']['wx_mch_id']);
  11. define('WXN_KEY', $payment_info['payment_config']['wx_key']);
  12. }
  13. /*mweb_url*/
  14. public function get_payform($order_info){
  15. require_once PLUGINS_PATH . '/payments/wxpay_native/lib/WxPay.Api.php';
  16. require_once PLUGINS_PATH . '/payments/wxpay_native/WxPay.NativePay.php';
  17. require_once PLUGINS_PATH . '/payments/wxpay_native/log.php';
  18. //统一下单
  19. $input = new WxPayUnifiedOrder();
  20. $input->SetBody(config('ds_config.site_name') . $order_info['pay_sn'] . '订单');
  21. $input->SetAttach($order_info['order_type']);
  22. $input->SetOut_trade_no($order_info['pay_sn'].'_'.TIMESTAMP);//31个字符,微信限制为32字符以内 TIMESTAMP 用来防止做随机数,用户支付订单后取消,已产生的订单不能重复支付
  23. $input->SetTotal_fee(bcmul($order_info['api_pay_amount'] , 100,0));
  24. $input->SetTime_start(date("YmdHis"));
  25. $input->SetTime_expire(date("YmdHis", TIMESTAMP + 600));
  26. $input->SetGoods_tag("");
  27. $input->SetNotify_url(str_replace('/index.php', '', HOME_SITE_URL) . '/payment/wxpay_h5_notify.html');
  28. $input->SetTrade_type("MWEB");
  29. $result = WxPayApi::unifiedOrder($input);
  30. //不同订单支付成功对应的跳转界面
  31. if($order_info['order_type'] == 'real_order'){
  32. $pay_type='pay_new';
  33. }elseif ($order_info['order_type'] == 'vr_order') {
  34. $pay_type='vr_pay_new';
  35. } elseif ($order_info['order_type'] == 'pd_order') {
  36. $pay_type='pd_pay';
  37. } elseif ($order_info['order_type'] == 'sj_order') {
  38. $pay_type='sj_pay';
  39. }
  40. $url = config('ds_config.h5_site_url').'/pages/member/buy/pay?notice=1&pay_sn='.$order_info['pay_sn'].'&pay_type='.$pay_type;
  41. if(input('param.uniapp')){
  42. $url = preg_replace('/^(http|https):\/\//','dsmall://',$url);
  43. }
  44. $mweb_url = $result['mweb_url'].'&redirect_url='.urlencode($url);
  45. echo '<script>window.location.href="'.$mweb_url.'"</script>';exit;
  46. // header("Location:".$mweb_url);
  47. // exit;
  48. }
  49. }