/** * 生成支付代码 * * @param array $order * 订单信息 * @param array $payment * 支付方式信息 */ function get_code($order, $payment) { $conf = new WxPayConf_pub($payment); //微信浏览器的JSAPI支付\ if (strpos($_SERVER['HTTP_USER_AGENT'], "MicroMessenger")) { $tools = new JsApi_pub($payment); $openid = $tools->GetOpenid(); $unifiedOrder = new UnifiedOrder_pub(); $returnrul = $conf->successurl; $unifiedOrder->setParameter("appid", $conf->wxpay_app_id); // appid $unifiedOrder->setParameter("openid", "{$openid}"); // openid $unifiedOrder->setParameter("body", $order['order_sn']); // 商品描述 $timeStamp = time(); // $out_trade_no = WxPayConf_pub::APPID."$timeStamp"; $unifiedOrder->setParameter("out_trade_no", $order['order_sn']); // 商户订单号 $unifiedOrder->setParameter("total_fee", intval($order['order_amount'] * 100)); // 总金额 $unifiedOrder->setParameter("spbill_create_ip", $_SERVER['REMOTE_ADDR']); $unifiedOrder->setParameter("notify_url", 'http://' . $_SERVER["HTTP_HOST"] . '/respond.php'); // 通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); // 交易类型 // 非必填参数,商户可根据实际情况选填 // $unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号 // $unifiedOrder->setParameter("device_info","XXXX");//设备号 // $unifiedOrder->setParameter("attach","XXXX");//附加数据 // $unifiedOrder->setParameter("time_start","XXXX");//交易起始时间 // $unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间 // $unifiedOrder->setParameter("goods_tag","XXXX");//商品标记 // $unifiedOrder->setParameter("openid","XXXX");//用户标识 // $unifiedOrder->setParameter("product_id","XXXX");//商品ID $prepay_id = $unifiedOrder->getPrepayId(); //var_dump($prepay_id); $jsApi = new JsApi_pub(); $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); $pay_online = $jsApi->getbutton($jsApiParameters, $returnrul); return $pay_online; } else { $native = new NativeLink_pub($payment); //var_dump($order);die(); $native->setParameter("body", $order['order_sn']); // 商品描述 $timeStamp = time(); // $out_trade_no = WxPayConf_pub::APPID."$timeStamp"; $native->setParameter("appid", $conf->wxpay_app_id); // openid $native->setParameter("out_trade_no", $order['order_sn']); // 商户订单号 $native->setParameter("total_fee", intval($order['order_amount'] * 100)); // 总金额 $native->setParameter("notify_url", $conf->notifyurl); // 通知地址 $native->setParameter("trade_type", "NATIVE"); // 交易类型 $native->setParameter("product_id", $order['order_id']); $url = $native->getUrl(); return $url; // // 非必填参数,商户可根据实际情况选填 // // $unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号 // // $unifiedOrder->setParameter("device_info","XXXX");//设备号 // // $unifiedOrder->setParameter("attach","XXXX");//附加数据 // $unifiedOrder->setParameter("time_start",date ( "YmdHis" ));//交易起始时间 // $unifiedOrder->setParameter("time_expire",date ( "YmdHis", time () + 600 ));//交易结束时间 // // $unifiedOrder->setParameter("goods_tag","XXXX");//商品标记 // // $unifiedOrder->setParameter("openid","XXXX");//用户标识 // // $unifiedOrder->setParameter("product_id","XXXX");//商品ID } }