/** * 生成支付代码 * @param array $order 订单信息 * @param array $payment 支付方式信息 */ function get_code($order, $payment, $direct = false) { //$uid = $_SESSION['user_name']; //$wxid = uidrwxid($uid); //var_dump($uid); //var_dump($wxid); //echo return_url('wxpay'); // @$openid=$_SESSION['sopenid']; //echo $_SESSION['sopenid']."dfdfds";exit; //echo $uid;exit; $openid = $_SESSION['xaphp_sopenid']; //测试 if (empty($openid)) { return ""; } //$openid = "oSxZVuNcC7qArMKsIgPeHeoHOydA"; $unifiedOrder = new UnifiedOrder_pub(); $conf = new WxPayConf_pub(); if ($order['extension_code'] == 'team_goods') { $returnrul = $conf->successurl . $order["order_id"] . "&team=1"; } else { $returnrul = $conf->successurl . $order["order_id"]; } //var_dump($returnrul); //http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] //exit; $unifiedOrder->setParameter("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("notify_url", $conf->notifyurl); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 $unifiedOrder->setParameter("is_subscribe", "Y"); //交易类型 // if(!empty($order['goods_name'])){ // $unifiedOrder->setParameter("body", mb_strlen($order['goods_name'],"utf-8")>30 ? mb_substr($order['goods_name'],0,30,'utf-8') : $order['goods_name'] ); // } //非必填参数,商户可根据实际情况选填 //$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(); $jsApi = new JsApi_pub(); $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); if ($direct) { $pay_online = $jsApi->getbutton2($jsApiParameters, $returnrul, $order); } else { $pay_online = $jsApi->getbutton($jsApiParameters, $returnrul, $order); } return $pay_online; }