/** * JSAPI * @throws \common\wechat\exception\WxPayException */ public function actionJspay() { try { //①、获取用户openid $tools = new JsApiPay(); $openId = $tools->GetOpenid(); //②、统一下单 $input = new WxPayUnifiedOrder(); $input->SetBody("test"); $input->SetAttach("test"); $input->SetOut_trade_no(WxPayConfig::$mchId . date("YmdHis")); $input->SetTotal_fee("1"); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag("test"); $input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php"); $input->SetTrade_type("JSAPI"); $input->SetOpenid($openId); $order = WxPayApi::unifiedOrder($input); $jsApiParameters = $tools->GetJsApiParameters($order); //获取共享收货地址js函数参数 $editAddress = $tools->GetEditAddressParameters(); return $this->render('js_api', ['editAddress' => $editAddress, 'jsApiParameters' => $jsApiParameters]); } catch (WxPayException $ex) { echo $ex->getMessage(); } }
/** * * 生成直接支付url,支付url有效期为2小时,模式二 * @param WxPayUnifiedOrder $input */ public function GetPayUrl($input) { if ($input->GetTrade_type() == "NATIVE") { $result = WxPayApi::unifiedOrder($input); return $result; } }
public function unifiedorder($openId, $product_id) { //统一下单 $input = new WxPayUnifiedOrder(); $input->SetBody("test"); $input->SetAttach("test"); $input->SetOut_trade_no(WxPayConfig::$mchId . date("YmdHis")); $input->SetTotal_fee("1"); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag("test"); $input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php"); $input->SetTrade_type("NATIVE"); $input->SetOpenid($openId); $input->SetProduct_id($product_id); $result = WxPayApi::unifiedOrder($input); // Log::DEBUG("unifiedorder:" . json_encode($result)); return $result; }