wxpay_minipro.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * 微信支付接口类
  4. * JSAPI 适用于微信内置浏览器访问WAP时支付
  5. */
  6. class wxpay_minipro {
  7. public function __construct($payment_info = array()) {
  8. define('WXN_APPID', $payment_info['payment_config']['xcx_appid']);
  9. define('WXN_APPSECRET', $payment_info['payment_config']['xcx_appsecret']);
  10. define('WXN_MCHID', $payment_info['payment_config']['xcx_mch_id']);
  11. define('WXN_KEY', $payment_info['payment_config']['xcx_key']);
  12. }
  13. public function get_payform($order_info) {
  14. //引入PC端微信公共类
  15. require_once PLUGINS_PATH . '/payments/wxpay_native/lib/WxPay.Api.php';
  16. require_once PLUGINS_PATH . '/payments/wxpay_native/WxPay.JsApiPay.php';
  17. //获取用户openid
  18. $tools = new JsApiPay();
  19. $openId = input('param.openid');
  20. //统一下单
  21. $input = new WxPayUnifiedOrder();
  22. $input->SetBody(config('ds_config.site_name') . $order_info['pay_sn'] . '订单');
  23. $input->SetAttach($order_info['order_type']);
  24. $input->SetOut_trade_no($order_info['pay_sn'].'_'.TIMESTAMP);//31个字符,微信限制为32字符以内 TIMESTAMP 用来防止做随机数,用户支付订单后取消,已产生的订单不能重复支付
  25. $input->SetTotal_fee(bcmul($order_info['api_pay_amount'] , 100,0));
  26. $input->SetTime_start(date("YmdHis"));
  27. $input->SetTime_expire(date("YmdHis", TIMESTAMP + 600));
  28. $input->SetGoods_tag("");
  29. $input->SetNotify_url(str_replace('/index.php', '', HOME_SITE_URL) . '/payment/wxpay_minipro_notify.html');
  30. $input->SetTrade_type("JSAPI");
  31. $input->SetOpenid($openId);
  32. $order = WxPayApi::unifiedOrder($input);
  33. if($order['return_code']=='FAIL'){
  34. ds_json_encode(10001,$order['return_msg']);
  35. }else{
  36. $jsApiParameters = $tools->GetJsApiParameters($order);
  37. ds_json_encode(10000,'',$jsApiParameters);
  38. }
  39. }
  40. }