function get_pay_url($charge_type, $pay_amount, $payment_config, $subject, $order_id, $model_id = null, $obj_id = null, $service = null, $sign_type = 'MD5', $show_url = 'index.php?do=user&view=finance&op=details') { global $_K, $uid, $username; $charge_type == 'order_charge' and $t = "订单充值" or $t = "余额充值"; $body = $t . "(from:" . $username . ")"; $notify = new NativePay(); $WxPayCfg = new WxPayCfg(); $Out_trade_no = $WxPayCfg->_mchid . date("YmdHis"); $attach = "charge-{$charge_type}-{$uid}-{$obj_id}-{$order_id}-{$model_id}-" . time(); $input = new WxPayUnifiedOrder(); $input->SetBody($body); $input->SetDetail($body); $input->SetAttach($attach); $input->SetOut_trade_no($Out_trade_no); $input->SetFee_type("CNY"); $input->SetTotal_fee($pay_amount * 100); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetNotify_url(BASE_WXPAY_URL . "notify.php"); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($obj_id); $result = $notify->GetPayUrl($input); $url2 = $result["code_url"]; keke_order_class::create_order_charge('online_charge', 'wxpay', null, $obj_id, $uid, $username, $pay_amount, 'wait', '用户充值', $Out_trade_no, null, $attach); $baseUrl = urlencode($url2); $data = array(); $data['url'] = BASE_WXPAY_URL . "qrcode.php?data=" . $baseUrl; $data['out_trade_no'] = $Out_trade_no; return $data; }
/** * 生成微信支付二维码 */ public static function qrcode($product_id, $body, $total_fee, $attach = '', $detail = '', $goods_tag = '') { // 处理金额 if (ENV_SCENE == 'dev') { $total_fee = 0.01; } $total_fee *= 100; $notify = new NativePay(); /** * 流程: * 1、调用统一下单,取得code_url,生成二维码 * 2、用户扫描二维码,进行支付 * 3、支付完成之后,微信服务器会通知支付成功 * 4、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php) */ $input = new WxPayUnifiedOrder(); $input->SetBody($body); $input->SetAttach($product_id); if (!empty($detail)) { $input->SetDetail($detail); } $input->SetOut_trade_no(WxPayConfig::$APPID . substr($product_id, 1)); $input->SetTotal_fee($total_fee); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); if (!empty($goods_tag)) { $input->SetGoods_tag($goods_tag); } $input->SetNotify_url(WxPayConfig::$NOTIFY_URL); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($product_id); $result = $notify->GetPayUrl($input); return $result["code_url"]; }
public function preOrder($param) { $order = new WxPayUnifiedOrder(); $order->SetOut_trade_no($param['out_trade_no']); $order->SetTotal_fee($param['total_fee'] * 100); $order->SetTrade_type('APP'); $order->SetBody($param['body']); $order->SetDetail($param['detail']); $order->SetNotify_url($this->_notify_url); $re = WxPayApi::unifiedOrder($order); if ($re['result_code'] == 'FAIL') { throw new Exception("微信 preorder 错误-" . $re['err_code_des'], 9001); } if ($re['return_code'] == 'FAIL') { throw new Exception("微信 preorder 错误-" . $re['return_msg'], 9001); } return $re; }
public function unifiedOrder($cart, $reference) { $total = (double) $cart->getOrderTotal(true, Cart::BOTH); $total = (int) ($total * 100); $detail = ''; $nbProducts = $cart->nbProducts(); if ($nbProducts > 1) { $detail = $this->module->l('Cart') . ' ' . $nbProducts . ' ' . $this->module->l('Products'); } else { $products = $cart->getProducts(); $detail = $products[0]['name']; } $time_start = date("YmdHis"); $time_expire = date("YmdHis", time() + WXP_TIMEOUT); if (WXP_TIMEZONE != Configuration::get('PS_TIMEZONE')) { $china_timezone = new DateTimeZone(WXP_TIMEZONE); $system_timezone = new DateTimeZone(Configuration::get('PS_TIMEZONE')); $start = new DateTime($time_start, $system_timezone); $start->setTimezone($china_timezone); $time_start = $start->format("YmdHis"); $expire = new DateTime($time_expire, $system_timezone); $expire->setTimezone($china_timezone); $time_expire = $expire->format("YmdHis"); } $notify = new NativePay(); $input = new WxPayUnifiedOrder(); $input->SetBody($detail); $input->SetDetail($detail); $input->SetOut_trade_no($reference); $input->SetTotal_fee($total); $input->SetTime_start($time_start); $input->SetTime_expire($time_expire); $input->SetNotify_url(Configuration::get('WEIXIN_NOTIFY_URL')); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($reference); $result = $notify->getPayUrl($input); if (isset($result["code_url"])) { return $result["code_url"]; } return false; }
function getWXURI($order_id) { $WxCfg = $this->getWXCfg(); $order = new WC_Order($order_id); $total = $order->get_total(); $totalFee = (int) ($total * 100); $input = new WxPayUnifiedOrder(); $input->SetBody("Shop Name: " . get_option('blogname')); $input->SetDetail(""); $input->SetAttach($order_id); $input->SetOut_trade_no(date("YmdHis")); if (!in_array($this->current_currency, array('RMB', 'CNY'))) { $totalFee = round($totalFee * $this->exchange_rate, 2); } $input->SetTotal_fee($totalFee); $date = new DateTime(); $date->setTimezone(new DateTimeZone('Asia/Shanghai')); $startTime = $date->format('YmdHis'); $expiredTime = $startTime + 600; $input->SetTime_start($startTime); $input->SetTime_expire($expiredTime); //$input->SetGoods_tag("tag"); $input->SetNotify_url($this->notify_url); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($order_id); $result = WxPayApi::unifiedOrder($input, 6, $WxCfg); Log::DEBUG('Response of WxPayApi::unifiedOrder:' . print_r($result, true)); return $result["code_url"]; }
/** * 统一下单接口 * * @param array $order 站内订单数组 * @param string $openId openid * @return string */ public static function unifiedOrder(array $order, $openId = '') { if (empty($order)) { return ''; } include_once WXPAY_SDK_ROOT . "unit/WxPay.JsApiPay.php"; //获取用户openid $tools = new JsApiPay(); if (empty($openId)) { $openId = $tools->GetOpenid(); } $wx_order_body = '女神送花(' . $order['player_id'] . '号)'; $order_detail = ($order['goods_type'] == 'flower' ? "送花(" : "送吻(") . $order['goods_amount'] . ")"; /* if (!empty($order['order_goods'])) { foreach ($order['order_goods'] As $g) { $order_detail .= $g['goods_name'].'('.$g['goods_price'].'x'.$g['goods_number'].")\n"; if (''==$wx_order_body) { $wx_order_body = mb_truncate($g['goods_name'], 27); } } $order_detail = rtrim($order_detail,"\n"); } */ //统一下单 if (1 || empty($order['pay_data1'])) { //订单状态可能会被后台更改,所以同一订单每次支付都要重新生成提交信息 if ('' == $wx_order_body) { $wx_order_body = '微信支付商品'; } $now = time(); $input = new WxPayUnifiedOrder(); $input->SetBody($wx_order_body); $input->SetDetail($order_detail); $input->SetAttach('simphp'); //商家自定义数据,原样返回 $input->SetOut_trade_no($order['order_sn']); $input->SetTotal_fee(intval($order['order_amount'] * 100)); //'分'为单位 $input->SetTime_start(date('YmdHis', $now)); $input->SetTime_expire(date('YmdHis', $now + 60 * 15)); //15分钟内支付有效 $input->SetGoods_tag(''); //商品标记,代金券或立减优惠功能的参数 $input->SetNotify_url(self::NOFIFY_URL); $input->SetTrade_type(self::TRADE_TYPE_JSAPI); $input->SetOpenid($openId); $order_wx = WxPayApi::unifiedOrder($input); //trace_debug('wxpay_order_wx', $order_wx); if ('SUCCESS' == $order_wx['return_code'] && 'SUCCESS' == $order_wx['result_code']) { //保存信息以防再次重复提交 $wxpay_data = ['appid' => $order_wx['appid'], 'mch_id' => $order_wx['mch_id'], 'trade_type' => $order_wx['trade_type'], 'prepay_id' => $order_wx['prepay_id']]; if (isset($order_wx['code_url'])) { $wxpay_data['code_url'] = $order_wx['code_url']; } Goods::orderUpdate(['pay_data1' => json_encode($wxpay_data)], $order['order_id']); } } else { $order_wx = json_decode($order['pay_data1'], true); } $jsApiParameters = $tools->GetJsApiParameters($order_wx); return $jsApiParameters; }