GetOpenid() public method

通过跳转获取用户的openid,跳转流程如下: 1、设置自己需要调回的url及其其他参数,跳转到微信服务器https://open.weixin.qq.com/connect/oauth2/authorize 2、微信服务处理完成之后会跳转回用户redirect_uri地址,此时会带上一些参数,如:code
public GetOpenid ( ) : 用户的openid
return 用户的openid
示例#1
0
 static function build_js_params()
 {
     //①、获取用户openid
     $tools = new JsApiPay();
     $openId = $tools->GetOpenid();
     pt_log($openId);
     //②、统一下单
     $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://demo.ptphp.com/wxpay/example/notify_test");
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = WxPayApi::unifiedOrder($input);
     pt_log($order);
     $jsApiParameters = $tools->GetJsApiParameters($order);
     pt_log($jsApiParameters);
     //获取共享收货地址js函数参数
     return $jsApiParameters;
 }
示例#2
0
 /**
  * 微信支付
  * @param $orderId
  * @return array
  * @throws \WxPayException
  */
 public function weiXinPay($orderId)
 {
     //①、获取用户openid
     $tools = new \JsApiPay();
     $openId = $tools->GetOpenid();
     if ($openId == -1) {
         return false;
     }
     //②、统一下单
     $orderInfo = ChargeOrder::getInstance()->getOne($orderId);
     $goods = ChargeGoods::getInstance()->getOne($orderInfo['charge_goods_id']);
     $input = new \WxPayUnifiedOrder();
     $input->SetBody("嘉瑞百合缘-【" . $goods['name'] . "】");
     $input->SetAttach("手机网站");
     $input->SetOut_trade_no($orderInfo['order_id']);
     $input->SetTotal_fee((string) $orderInfo['money']);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetNotify_url("http://wechat.baihey.com/wap/charge/notify-url");
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = \WxPayApi::unifiedOrder($input);
     $jsApiParameters = $tools->GetJsApiParameters($order);
     return ['orderInfo' => $orderInfo, 'jsApiParameters' => $jsApiParameters];
 }
示例#3
0
 public function wxJsPay()
 {
     $list = isset($_SESSION['orderinfo']) ? $_SESSION['orderinfo'] : array();
     if (!isset($_SESSION['orderinfo'])) {
         header("Location:" . appurl('getMeOrder'));
         die;
     }
     //验证是否能预定
     if (isset($_SESSION['orderList'])) {
         foreach ($_SESSION['orderList'] as $key => $value) {
             $this->checkCanSum($value['bookid'], $value);
             if (!$this->checkBook($value['bookid'])) {
                 $this->alert($value['title'] . '已经售卖结束');
                 exit;
             }
         }
     }
     //初始化日志
     $logHandler = new CLogFileHandler("../logs/" . date('Y-m-d') . '.log');
     $log = Log::Init($logHandler, 15);
     //①、获取用户openid
     $tools = new JsApiPay();
     $openId = $tools->GetOpenid();
     //②、统一下单
     //价钱转成分
     $totalFee = $list['allPrice'] * 100;
     $input = new WxPayUnifiedOrder();
     $input->SetBody("订单");
     $input->SetAttach("订单");
     $input->SetOut_trade_no($list['orderid']);
     $input->SetTotal_fee($totalFee);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetGoods_tag("订单");
     $input->SetNotify_url(appurl('callBack'));
     // "http://paysdk.weixin.qq.com/example/notify.php"
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = WxPayApi::unifiedOrder($input);
     echo '<font color="#f00"><b>支付中,客官请稍后....</b></font><br/>';
     // $this->printf_info($order);
     $jsApiParameters = $tools->GetJsApiParameters($order);
     //获取共享收货地址js函数参数
     $editAddress = $tools->GetEditAddressParameters();
     //③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
     /**
      * 注意:
      * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功
      * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”,
      * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html)
      */
     $data = array('jsApiParameters' => $jsApiParameters, 'editAddress' => $editAddress, 'orderid' => $list['orderid'], 'pageTitle' => '支付');
     unset($_SESSION['orderinfo']);
     $this->layoutRender('/wxpay', $data);
 }
示例#4
0
文件: function.php 项目: Jitlee/YYG
function get_user_open_id()
{
    $openId = session('openid') . '';
    if (strlen($openId) > 10) {
        return $openId . '';
    } else {
        //1、获取openid
        vendor('Weixinpay.WxPayJsApiPay');
        $tools = new \JsApiPay();
        $openId = $tools->GetOpenid() . '';
        session('openid', $openId);
        return $openId . '';
    }
}
示例#5
0
文件: Api.php 项目: hejxing/jt
 /**
  * 统一下单
  *
  * @param $amount
  *
  * @return string
  */
 private function getUnifiedOrder($amount)
 {
     $tools = new \JsApiPay();
     $openId = $tools->GetOpenid();
     //获取用户openID
     $outTradeNo = \tools\Tools::uuid();
     $input = new \WxPayUnifiedOrder();
     $input->SetBody($this->data['memo']);
     $input->SetAttach($this->data['id']);
     $input->SetOut_trade_no($outTradeNo);
     $input->SetTotal_fee($this->amount);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetGoods_tag($this->data['memo']);
     $input->SetNotify_url($this->notify_url);
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = \WxPayApi::unifiedOrder($input);
     $jsApiParameters = $tools->GetJsApiParameters($order);
     //获取共享收货地址js函数参数
     $editAddress = $tools->GetEditAddressParameters();
     return ['jsApiParameters' => $jsApiParameters, 'editAddress' => $editAddress, 'amount' => $amount, 'orderId' => $this->data['id']];
 }
示例#6
0
文件: jsapi.php 项目: king3388/king
require_once "../lib/WxPay.Api.php";
require_once "WxPay.JsApiPay.php";
require_once 'log.php';
//初始化日志
$logHandler = new CLogFileHandler("../logs/" . date('Y-m-d') . '.log');
$log = Log::Init($logHandler, 15);
//打印输出数组信息
function printf_info($data)
{
    foreach ($data as $key => $value) {
        echo "<font color='#00ff55;'>{$key}</font> : {$value} <br/>";
    }
}
//①、获取用户openid
$tools = new JsApiPay();
$openId = $tools->GetOpenid();
//②、统一下单
$input = new WxPayUnifiedOrder();
$input->SetBody("6dygjsapi");
$input->SetAttach("6dygjsapi");
$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("6dygjsapi");
$input->SetNotify_url("http://mm.lmcity.cn/weipay/example/notify.php");
$input->SetTrade_type("JSAPI");
$input->SetOpenid($openId);
$order = WxPayApi::unifiedOrder($input);
echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>';
printf_info($order);
示例#7
0
  private function wxJsPay($request)
  {
    $state = $request->input('state');

    $decodeObject = json_decode($state);

    $user = Auth::user();

    $order_code = $decodeObject->order_code;

    $order = Order::where('code', '=', $order_code)->first();

    if (empty($order->id)) {
    
      //todo
    
    } else if ($order->status > 0) {
    
      return view('mobile/payed');
    
    }

    $good = Good::where('id', '=', $order->gid)->first();

    $orderPrice = OrderPrice::where('oid', '=', $order->id)->first();

    $receiver = ReceiverInfo::find($order->rid);

    require_once "lib/WxPay.Api.php";  

    require_once "lib/WxPay.JsApiPay.php";

    $notify_url = $this->debug ? "http://www.51linpai.com:8000/order/wxpay/" : "http://www.51linpai.com/order/wxpay/";

    $tools = new \JsApiPay();

    $openId = $tools->GetOpenid("", null);

    $input = new \WxPayUnifiedOrder();
    $input->SetBody($good->name);
    $input->SetAttach($good->code);
    $input->SetOut_trade_no($order->code);
    $input->SetTotal_fee($orderPrice->final_price * 100);
    $input->SetTime_start(date("YmdHis"));
    $input->SetTime_expire(date("YmdHis", time() + 600));
    $input->SetGoods_tag($good->code);
    $input->SetNotify_url($notify_url);
    $input->SetTrade_type("JSAPI");
    $input->SetOpenid($openId);
    $jsWxOrder = \WxPayApi::unifiedOrder($input);
    $jsApiParameters = $tools->GetJsApiParameters($jsWxOrder);

    //获取共享收货地址js函数参数
    $editAddress = $tools->GetEditAddressParameters();

    $data = [

        'editAddress' => $editAddress,

        'jsApiParameters' => $jsApiParameters,

        'order_code' => $order->code,

        'price' => $orderPrice->final_price,

        'address' =>  $receiver->city . ' ' . $receiver->district . ' ' . $receiver->address,

        'step' => 4,

        'header' => '支付订单'
      
      ];
    
    return view('mobile/wechat_js_pay', $data);
  
  }
 public function actionWxpay($order)
 {
     $model = Order::findOne(['order_sn' => $order, 'status' => Order::STATUS_UNPAID]);
     if (!$model) {
         throw new BadRequestHttpException('参数错误!');
     }
     require_once Yii::getAlias('@vendor') . "/payment/wxpay/lib/WxPay.Api.php";
     require_once Yii::getAlias('@vendor') . "/payment/wxpay/lib/WxPay.JsApiPay.php";
     try {
         $tools = new \JsApiPay();
         $openId = $tools->GetOpenid();
         $input = new \WxPayUnifiedOrder();
         $input->SetBody('笑e购(xiaoego.com)订单,' . $model->description);
         $input->SetOut_trade_no($model->order_sn);
         $input->SetTotal_fee(bcmul($model->real_fee, 100));
         $input->SetTime_start(date("YmdHis", $model->created_at));
         $input->SetTime_expire(date("YmdHis", $model->timeout));
         $input->SetNotify_url(Url::to(['/payment/wxpay-order-notify'], true));
         $input->SetTrade_type("JSAPI");
         $input->SetOpenid($openId);
         $orderform = \WxPayApi::unifiedOrder($input);
         $jsApiParameters = $tools->GetJsApiParameters($orderform);
     } catch (\Exception $e) {
         Yii::error("用户请求支付订单失败!订单号:{$order},支付平台:wxpay");
         throw new BadRequestHttpException($e->getMessage());
     }
     Yii::info("用户请求支付订单成功!订单号:{$order},支付平台:wxpay");
     return $this->renderPartial('wxpay', ['model' => $model, 'jsApiParameters' => $jsApiParameters]);
 }
示例#9
0
 /**
  * 统一下单接口
  * 
  * @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;
 }
示例#10
0
<?php

$baseUrl = Yii::app()->baseUrl;
Yii::app()->clientScript->registerCssFile($baseUrl . '/css/cartlist.css');
$this->setPageTitle('支付');
$orderProductListPay = array();
$orderProductListPay = OrderList::WxPayOrderList($dpid, $orderId, 1, 0, 1);
$pricePay = OrderList::WxPayOrderPrice($orderProductListPay);
$pricePayArr = explode(':', $pricePay);
$orderPricePay = $pricePayArr[0];
$orderPayNum = $pricePayArr[1];
$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
//①、获取用户openid
$tools = new JsApiPay();
$openId = $tools->GetOpenid($url);
//②、统一下单
$input = new WxPayUnifiedOrder();
$input->SetBody("test");
$input->SetAttach("test");
$input->SetOut_trade_no($orderId);
$input->SetTotal_fee($orderPricePay * 100);
$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);
$orderInfo = WxPayApi::unifiedOrder($input);
$jsApiParameters = $tools->GetJsApiParameters($orderInfo);
if ($orderProductListPay) {
    ?>
示例#11
0
 public function thirdpay()
 {
     $orderno = $_POST['orderno'] . '';
     if ($orderno) {
         session("orderno", $orderno);
         $Body = $_POST['goodsName'] . '';
         $accountmoney = $_POST['accountmoney'];
         //帐户余额支付
         $accountscore = $_POST['accountscore'];
         //低扣积分
         $tfee = $_POST['amount'];
         //三方支付金额
         $paytype = $_POST['paytype'] . '';
         //三方支付金额
         $mMPay = D('M/MemberPay');
         $dataInfo = $mMPay->GetByPayNo($orderno);
         $dataInfo['amount'] = $tfee;
         $dataInfo['amountStatus'] = 0;
         $dataInfo['accountmoney'] = $accountmoney;
         $dataInfo['accountmoneyStatus'] = 0;
         $dataInfo['accountscore'] = $accountscore;
         $dataInfo['accountscoreStatus'] = 0;
         $dataInfo['thirdpaytype'] = $paytype;
         $rdpay = $mMPay->UpdatePay($dataInfo);
         if ($rdpay['status'] !== 1) {
             echo '更新状态失败。' . $rd['status'];
             $this->display();
             return;
         }
     } else {
         $orderno = session("orderno");
         if (empty($orderno)) {
             $this->display("Pay/error");
             return;
         }
         $mMPay = D('M/MemberPay');
         $dataInfo = $mMPay->GetByPayNo($orderno);
         if (empty($dataInfo)) {
             return;
         }
         $tfee = $dataInfo['amount'];
         $accountmoney = $dataInfo['accountmoney'];
         $accountscore = $dataInfo['accountscore'];
         $paytype = $dataInfo['thirdpaytype'];
     }
     if ($dataInfo["Status"] == 99) {
         $this->display("Pay/success");
         return;
     }
     //		//更新各支付金额
     if ($paytype == "wx") {
         vendor('Weixinpay.WxPayJsApiPay');
         //
         //			//1、获取openid
         $tools = new \JsApiPay();
         $openId = $tools->GetOpenid();
         $this->assign('money', $tfee);
         $tfee = $tfee * 100;
         //整数单位为分
         $uid = (int) session("uid");
         if ($uid == 104) {
             $tfee = 1;
         }
         $this->assign('title', $Body);
         //
         $Body = "订单支付";
         if ($dataInfo["PayType"] == "recharge") {
             $subject = '粗卡充值';
             $body = '粗卡充值';
         }
         $input = new \WxPayUnifiedOrder();
         $input->SetBody($Body);
         $input->SetAttach($orderno);
         $input->SetOut_trade_no(\WxPayConfig::MCHID . date("YmdHis"));
         $input->SetTotal_fee($tfee);
         $input->SetTime_start(date("YmdHis"));
         $input->SetTime_expire(date("YmdHis", time() + 600));
         $input->SetGoods_tag("Goods");
         $input->SetNotify_url("http://cukayun.cn/index.php/M/Pay/notify/");
         //支付回调地址,这里改成你自己的回调地址。
         $input->SetTrade_type("JSAPI");
         $input->SetOpenid($openId);
         //			echo dump($input);
         $order = \WxPayApi::unifiedOrder($input);
         //			echo dump($order);
         $jsApiParameters = $tools->GetJsApiParameters($order);
         $this->jsApiParameters = $jsApiParameters;
         //与用户的openid作一个比较
         $this->display("thirdpay");
     } else {
         header('Location:' . U('PayAli/index', '', '') . "/orderno/{$orderno}");
     }
 }
示例#12
0
 /**
  * 获取微支付预支付订单
  * @param $out_trade_no
  * @param $goods
  * @param $total_fee
  * @param $body
  * @param $attach
  * @param $notify_url
  * @return \成功时返回
  */
 public static function GrantWxpayUnifiedOrder($out_trade_no, $goods, $total_fee, $body, $attach, $notify_url, $return_url)
 {
     require_once __DIR__ . "/../wxpay/WxPay.Api.php";
     require_once __DIR__ . "/../wxpay/WxPay.JsApiPay.php";
     require_once __DIR__ . "/../common/log.php";
     $tools = new \JsApiPay();
     $openId = $tools->GetOpenid($return_url);
     $input = new \WxPayUnifiedOrder();
     $input->SetBody($body);
     $input->SetAttach($attach);
     $input->SetOut_trade_no(time() . $out_trade_no);
     $input->SetTotal_fee(intval($total_fee * 100));
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetGoods_tag($goods);
     $input->SetNotify_url($notify_url);
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $result['order'] = \WxPayApi::unifiedOrder($input);
     $result['jsApiParameters'] = $tools->GetJsApiParameters($result['order']);
     //获取共享收货地址js函数参数
     //        $result['editAddress'] = $tools->GetEditAddressParameters();
     return $result;
 }