public function unifiedorder($openId, $product_id, $data) { //统一下单 $input = new UnifiedOrder(); $input->SetBody($data['body']); if (isset($data['attach'])) { $input->SetAttach($data['attach']); } $input->SetOut_trade_no($data['out_trade_no']); $input->SetTotal_fee($data['total_fee']); if (isset($data['time_start'])) { $input->SetTime_start($data['time_start']); } if (isset($data['time_expire'])) { $input->SetTime_expire($data['time_expire']); } if (isset($data['goods_tag'])) { $input->SetGoods_tag($data['goods_tag']); } if (isset($data['notify_url'])) { $input->SetNotify_url($data['notify_url']); } if (isset($data['spbill_create_ip'])) { $input->SetSpbill_create_ip($data['spbill_create_ip']); } $input->SetTrade_type('NATIVE'); $input->SetOpenid($openId); $input->SetProduct_id($product_id); $result = Api::unifiedOrder($input); return $result; }
public function createOrder($data) { if (!isset($data['body']) || empty($data['body'])) { throw new Exception('商品描述缺少'); } if (!isset($data['out_trade_no']) || empty($data['out_trade_no'])) { throw new Exception('商户订单号缺少'); } if (!isset($data['total_fee']) || empty($data['total_fee'])) { throw new Exception('总金额缺少'); } $input = new UnifiedOrder(); $input->SetBody($data['body']); if (isset($data['attach'])) { $input->SetAttach($data['attach']); } $input->SetOut_trade_no($data['out_trade_no']); $input->SetTotal_fee($data['total_fee']); if (isset($data['time_start'])) { $input->SetTime_start($data['time_start']); } if (isset($data['time_expire'])) { $input->SetTime_expire($data['time_expire']); } if (isset($data['goods_tag'])) { $input->SetGoods_tag($data['goods_tag']); } if (isset($data['notify_url'])) { $input->SetNotify_url($data['notify_url']); } if (isset($data['spbill_create_ip'])) { $input->SetSpbill_create_ip($data['spbill_create_ip']); } $input->SetTrade_type('JSAPI'); if (isset($data['product_id'])) { $input->SetProduct_id($data['product_id']); } if (isset($data['openid'])) { $input->SetOpenid($data['openid']); } $order = Api::unifiedOrder($input); $jsApiParameters = $this->GetJsApiParameters($order); //返回JSAPI信息 return $jsApiParameters; }
/** * * 生成直接支付url,支付url有效期为2小时,模式二 * @param Array $data */ private function getPayUrl(array $data) { if (!isset($data['body']) || empty($data['body'])) { throw new Exception('商品描述缺少'); } if (!isset($data['out_trade_no']) || empty($data['out_trade_no'])) { throw new Exception('商户订单号缺少'); } if (!isset($data['total_fee']) || empty($data['total_fee'])) { throw new Exception('总金额缺少'); } // // APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。 // if (!isset($data['spbill_create_ip']) || empty($data['spbill_create_ip'])) { // throw new Exception('终端IP缺少'); // } $input = new UnifiedOrder(); $input->SetBody($data['body']); if (isset($data['attach'])) { $input->SetAttach($data['attach']); } $input->SetOut_trade_no($data['out_trade_no']); $input->SetTotal_fee($data['total_fee']); //单位分 if (isset($data['time_start'])) { $input->SetTime_start($data['time_start']); } if (isset($data['time_expire'])) { $input->SetTime_expire($data['time_expire']); } if (isset($data['goods_tag'])) { $input->SetGoods_tag($data['goods_tag']); } if (isset($data['notify_url'])) { $input->SetNotify_url($data['notify_url']); } if (isset($data['spbill_create_ip'])) { $input->SetSpbill_create_ip($data['spbill_create_ip']); } $input->SetTrade_type('NATIVE'); $input->SetProduct_id($data['product_id']); $result = Api::unifiedOrder($input); return $result['code_url']; }