Esempio n. 1
0
/**
 * 生成支付接口内容
 * @param $data
 * @param bool $debug
 * @return json
 */
function jsapipay($data, $debug = false)
{
    // C('weixin.weixin_')
    //①、获取用户openid
    $tools = new JsApiPay();
    //    $openId = $tools->GetOpenid();
    if (!empty($data['openid'])) {
        $openId = $data['openid'];
    } else {
        echo "empty openid";
        die;
    }
    //②、统一下单
    $input = new WxPayUnifiedOrder();
    $input->SetBody($data['body']);
    $input->SetAttach($data['attach']);
    $input->SetOut_trade_no($data['order_sn']);
    $input->SetTotal_fee($data['total_fee']);
    $input->SetTime_start(date("YmdHis"));
    $input->SetTime_expire(date("YmdHis", time() + 600));
    $input->SetGoods_tag($data['goods_tag']);
    $input->SetNotify_url("http://{$_SERVER[HTTP_HOST]}/weixin/notify.html");
    $input->SetTrade_type("JSAPI");
    $input->SetOpenid($openId);
    $order = WxPayApi::unifiedOrder($input);
    if ($debug) {
        echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>';
        printf_info($order);
    }
    $jsApiParameters = $tools->GetJsApiParameters($order);
    return $jsApiParameters;
}
Esempio n. 2
0
 /**
  * 
  * 生成直接支付url,支付url有效期为2小时,模式二
  * @param UnifiedOrderInput $input
  */
 public function GetPayUrl($input)
 {
     if ($input->GetTrade_type() == "NATIVE") {
         $result = WxPayApi::unifiedOrder($input);
         return $result;
     }
 }
Esempio n. 3
0
 /**
  * 组装包含支付信息的url(模式2)
  */
 public function get_payurl()
 {
     require_once BASE_PATH . '/api/payment/wxpay/lib/WxPay.Api.php';
     require_once BASE_PATH . '/api/payment/wxpay/WxPay.NativePay.php';
     require_once BASE_PATH . '/api/payment/wxpay/log.php';
     $logHandler = new CLogFileHandler(BASE_DATA_PATH . '/log/wxpay/' . date('Y-m-d') . '.log');
     $Logwx = Logwx::Init($logHandler, 15);
     //统一下单
     $input = new WxPayUnifiedOrder();
     $input->SetBody($this->_order_info['pay_sn'] . '订单');
     //         $input->SetBody(C('site_name').'订单');
     $input->SetAttach($this->_order_info['order_type'] == 'vr_order' ? 'v' : 'r');
     $input->SetOut_trade_no($this->_order_info['pay_sn']);
     $input->SetTotal_fee($this->_order_info['api_pay_amount'] * 100);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 3600));
     $input->SetGoods_tag('');
     $input->SetNotify_url(SHOP_SITE_URL . '/api/payment/wxpay/notify_url.php');
     $input->SetTrade_type("NATIVE");
     //$input->SetOpenid($openId);
     $input->SetProduct_id($this->_order_info['pay_sn']);
     $result = WxPayApi::unifiedOrder($input);
     //         header("Content-type:text/html;charset=utf-8");
     //         print_R($result);exit;
     Logwx::DEBUG("unifiedorder-:" . json_encode($result));
     return $result["code_url"];
 }
Esempio n. 4
0
 public function GetOrderInfo($input)
 {
     if ($input->GetTrade_type() == "APP") {
         $result = WxPayApi::unifiedOrder($input, true);
         return $result;
     }
 }
Esempio n. 5
0
 /**
  * jsapi支付
  * @param string  $user_id    用户id
  * @param int     $order_id
  * @param string  $order_sn   订单号
  * @param int     $total_fee  费用
  * @param string  $body       商品或支付单简要描述
  * @param string  $goods_tag  商品标记
  * @param string  $attach     自定义数据
  * @return array
  */
 public function JsApiPay($user_id, $order_id, $order_sn, $total_fee, $body = '', $goods_tag = '', $attach = '')
 {
     if (empty($user_id) || empty($total_fee)) {
         return ['status' => -1, 'message' => '数据错误'];
     }
     $tools = new JsApiPay();
     $openId = UserModel::instance()->getOpenId($user_id);
     if (empty($openId)) {
         $openId = $tools->GetOpenid();
         //             return ['status'=> -2 , 'message'=>'user_id错误'];
     }
     $input = new \WxPayUnifiedOrder();
     $input->SetBody($body);
     $input->SetAttach($attach);
     $input->SetOut_trade_no($order_sn);
     //\WxPayConfig::MCHID.date("YmdHis")
     $input->SetTotal_fee($total_fee);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetGoods_tag($goods_tag);
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = \WxPayApi::unifiedOrder($input);
     if ($order['return_code'] != 'SUCCESS') {
         return ['status' => -10, 'message' => $order['return_msg']];
     }
     $jsApiParameters = $tools->GetJsApiParameters($order);
     $this->addPayLog($openId, $order_id, $input);
     return ['status' => 1, 'message' => $jsApiParameters];
 }
Esempio n. 6
0
 public function unifiedorder($openId, $product_id)
 {
     //得到支付金额
     $order_pay_info = Model('order')->getOrderPayInfo(array('pay_sn' => $product_id));
     if (empty($order_pay_info)) {
         $condition = array();
         $condition['order_sn'] = $product_id;
         $condition['order_state'] = ORDER_STATE_NEW;
         $order_info = Model('vr_order')->getOrderInfo($condition, 'sum(order_amount-rcb_amount-pd_amount) as order_amount');
         $attach = 'v';
     } else {
         $condition = array();
         $condition['pay_sn'] = $product_id;
         $condition['order_state'] = ORDER_STATE_NEW;
         $order_info = Model('order')->getOrderInfo($condition, array(), 'sum(order_amount-rcb_amount-pd_amount) as order_amount');
         $attach = 'r';
     }
     //统一下单
     $input = new WxPayUnifiedOrder();
     $input->SetBody($product_id . '订单');
     // 		$input->SetBody(C('site_name').'订单');
     $input->SetAttach($attach);
     $input->SetOut_trade_no($product_id);
     $input->SetTotal_fee($order_info['order_amount'] * 100);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 3600));
     $input->SetGoods_tag('');
     $input->SetNotify_url(SHOP_SITE_URL . '/api/payment/wxpay/notify_url.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;
 }
Esempio n. 7
0
 /** 二维码订单 */
 public function generateQrOrder()
 {
     $input = $this->unifiedOrder();
     $input->SetTrade_type("NATIVE");
     $input->SetProduct_id("123456789");
     $order = \WxPayApi::unifiedOrder($input);
     $qrUrl = $order["code_url"];
     return $qrUrl;
 }
Esempio n. 8
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);
 }
Esempio n. 9
0
 /** 二维码订单 */
 public function generateQrOrder($scheme)
 {
     $user = Yii::$app->session->get('user');
     $input = $this->unifiedOrder($scheme['payMoney']);
     $input->SetTrade_type("NATIVE");
     $input->SetProduct_id("123456789");
     $input->SetAttach($user['userId'] . "|" . $scheme['getBitcoin']);
     //传递用户id和获取到的云豆数
     $order = \WxPayApi::unifiedOrder($input);
     $qrUrl = $order["code_url"];
     return $qrUrl;
 }
Esempio n. 10
0
 public function getJsApiParameters($out_trade_no = '', $fee = '', $openId = '')
 {
     $input = new WxPayUnifiedOrder();
     $input->SetBody("购买相册打印服务");
     $input->SetOut_trade_no($out_trade_no);
     $input->SetTotal_fee($fee);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetNotify_url('http://api.dayinxiangsh.com/1.0/pay/callback');
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = WxPayApi::unifiedOrder($input);
     $jsApiParameters = $this->getParameters($order);
     return $jsApiParameters;
 }
Esempio n. 11
0
function getPrepayId($total_amount, $order_number, $attach)
{
    $input = new WxPayUnifiedOrder();
    $input->SetBody("美果优鲜订单");
    $input->SetAttach("缤纷水果");
    $input->SetOut_trade_no($attach);
    $input->SetTotal_fee($total_amount * 100);
    $input->SetAttach($order_number);
    $input->SetTime_start(date("YmdHis"));
    $input->SetTime_expire(date("YmdHis", time() + 600));
    $input->SetGoods_tag("商品标签");
    $input->SetNotify_url("https://dev1.meiguoyouxian.com/magento/custom/api/util/wx.php");
    $input->SetTrade_type("APP");
    $order = WxPayApi::unifiedOrder($input);
    return $order;
}
Esempio n. 12
0
 public function preOrder($param)
 {
     $order = new WxPayUnifiedOrder();
     $order->SetOut_trade_no($param['out_trade_no']);
     $order->SetTotal_fee($param['total_fee'] * 100);
     $order->SetTrade_type('APP');
     $order->SetBody($param['body']);
     $order->SetDetail($param['detail']);
     $order->SetNotify_url($this->_notify_url);
     $re = WxPayApi::unifiedOrder($order);
     if ($re['result_code'] == 'FAIL') {
         throw new Exception("微信 preorder 错误-" . $re['err_code_des'], 9001);
     }
     if ($re['return_code'] == 'FAIL') {
         throw new Exception("微信 preorder 错误-" . $re['return_msg'], 9001);
     }
     return $re;
 }
 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(Config::API_NOTIFY_URL);
     $input->SetTrade_type("NATIVE");
     $input->SetOpenid($openId);
     $input->SetProduct_id($product_id);
     $result = WxPayApi::unifiedOrder($input, Config::API_TIMEOUT);
     Log::DEBUG("unifiedorder:" . json_encode($result));
     return $result;
 }
Esempio n. 14
0
 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;
 }
Esempio n. 15
0
File: Api.php Progetto: 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']];
 }
 public function pay_get()
 {
     $order = I('get.order', '');
     $m = M('orders');
     // $map['from_member_id'] = $this->uid;
     $map['order_number'] = $order;
     // $map['status'] = 0;
     $info = $m->where($map)->find();
     if (empty($info)) {
         //未支付订单不存在
         $this->error(5015);
     }
     $total = $info['total'] * 100;
     $describe = 'testname';
     require_once APP_PATH . "SDK/Payment/wechat/lib/WxPay.Api.php";
     $input = new \WxPayUnifiedOrder();
     //设置公众账号ID
     $input->SetAppid(\WxPayConfig::APPID);
     //设置商户号
     $input->SetMch_id(\WxPayConfig::MCHID);
     //设置随机字符串
     $input->SetNonce_str(\WxPayApi::getNonceStr());
     //设置商品描述
     $input->SetBody($describe);
     //设置商户订单号
     $input->SetOut_trade_no($info['order_number']);
     //设置总金额
     $input->SetTotal_fee($total);
     //设置终端IP
     $input->SetSpbill_create_ip(get_client_ip());
     //设置通知地址
     $input->SetNotify_url(U('Wxpay/callback@api'));
     //设置交易类型
     $input->SetTrade_type('APP');
     $order = \WxPayApi::unifiedOrder($input);
     $this->success($order);
 }
Esempio n. 17
0
 public function pay()
 {
     require_once 'Weixinpay/WxPayData.class.php';
     require_once 'Weixinpay/WxPayApi.class.php';
     require_once 'Weixinpay/WxPayJsApiPay.php';
     // require_once ('Weixinpay/log.php');
     $paymentId = $_GET['paymentId'];
     $token = $_GET['token'];
     $body = $_GET['orderName'];
     $orderNo = $_GET['orderNumber'];
     if ($orderNo == "") {
         $orderNo = $_GET['single_orderid'];
     }
     $totalFee = $_GET['price'] * 100;
     // 单位为分
     // $paytype=$_GET['paytype'];
     $tools = new \JsApiPay();
     // $openId = $tools->GetOpenid();
     // $openId=$_GET['wecha_id'];
     // $openId=get_openid();
     // dump($openId);
     // die();
     // // dump($openId);
     //         $openId='orgF0t-HyMrDJHFOl9GAkENyu6i0';
     // dump('45456');
     $openId = $this->getPaymentOpenid();
     //         dump(session('paymentinfo'));
     //         dump($openId);
     //         dump('1232');die;
     // 统一下单
     import('Weixinpay.WxPayData');
     $input = new \WxPayUnifiedOrder();
     $input->SetBody($body);
     // $input->SetAttach("test");
     $input->SetOut_trade_no($orderNo);
     $input->SetTotal_fee($totalFee);
     // $input->SetTime_start(date("YmdHis"));
     // $input->SetTime_expire(date("YmdHis", time() + 600));
     // $input->SetGoods_tag("test");
     $input->SetNotify_url("Weixinpay/notify.php");
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = \WxPayApi::unifiedOrder($input);
     //         echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>';
     //dump($order);
     //         die;
     $jsApiParameters = $tools->GetJsApiParameters($order);
     //  dump($jsApiParameters);
     $returnUrl = addons_url('Payment://Weixin/payOK');
     header('Location:' . SITE_URL . '/WxpayAPI/unifiedorder.php?jsApiParameters=' . $jsApiParameters . '&returnurl=' . $returnUrl . '&totalfee=' . $_GET['price'] . '&paymentId=' . $paymentId);
     // echo $jsApiParameters;
     // die;
     // session('jsaparams',$jsApiParameters);
     // $_COOKIE['jsaparams']=$jsApiParameters;
     // $from=$_GET['from'];
     // if($from!='shop'){
     // $from=$this->doFromStr($_GET['from']);
     // }
     // //$returnUrl = '/index.php?g=Wap&m=' . $from . '&a=payReturn&token=' . $_GET ['token'] . '&wecha_id=' . $_GET ['wecha_id'] . '&orderid=' . $orderNo;
     // $returnUrl=addons_url('Payment://Weixin/payOK');
     // //$this->assign ( 'returnUrl', $returnUrl );
     // $this->assign ( 'jsApiParameters', $jsApiParameters );
     // $this->assign ( 'price', $_GET['price'] );
     // die;
     // header('Location:http://'.$_SERVER['HTTP_HOST'].'/weishi/WxpayAPI/unifiedorder.php?body='.$body.'&out_trade_no='.$orderNo.'&totalfee='.$totalFee.'&openid='.$openId.'&returnurl='.$returnUrl);
 }
Esempio n. 18
0
 public function wxpay()
 {
     //ajaxErrReturn('订单号必须');exit;
     if (!$_REQUEST['order_id'] && $_REQUEST['mo_id']) {
         ajaxErrReturn('订单号必须');
     }
     $model = M('order');
     if ($_REQUEST['order_id']) {
         $data['order_id'] = $_REQUEST['order_id'];
         $out_trade_no = $_REQUEST['order_id'];
     }
     if ($_GET['mo_id']) {
         $data['mo_id'] = $_REQUEST['mo_id'];
         $out_trade_no = $_REQUEST['mo_id'];
     }
     $data['member_id'] = $this->user['id'];
     $orders = $model->field('id,title,order_id,actual_paid,status')->where($data)->select();
     if (!$orders) {
         ajaxErrReturn('订单不存在');
     }
     $total_fee = 0;
     $title = '';
     foreach ($orders as $key => $order) {
         $total_fee += $order['actual_paid'];
         $titles[] = $order['title'];
         if ($order['status'] != 0) {
             ajaxErrReturn($order['order_id'] . '订单状态错误');
         }
     }
     $body = implode(',', $titles);
     $body = $body;
     $total_fee = $total_fee * 100;
     $total_fee = (string) $total_fee;
     require_once "../wxpay/lib/WxPay.Api.php";
     $input = new WxPayUnifiedOrder();
     $input->SetBody($body);
     //$input->SetAttach("test");
     $input->SetOut_trade_no($out_trade_no);
     $input->SetTotal_fee($total_fee);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     if ($_REQUEST['order_id']) {
         //单一订单支付
         $input->SetNotify_url(C('SITE_URL') . '/index.php/Wx_Payment/notify');
     }
     if ($_REQUEST['mo_id']) {
         //多订单合并支付
         $input->SetNotify_url(C('SITE_URL') . '/index.php/Wx_Payment/notify_merge');
     }
     //$input->SetNotify_url(C('SITE_URL') . '/index.php/Wx_Payment/notify_merge');
     $input->SetTrade_type("APP");
     //$input->SetOpenid($openId);
     $order = WxPayApi::unifiedOrder($input);
     $msg['appid'] = $order['appid'];
     $msg['partnerid'] = $order['mch_id'];
     $msg['prepayid'] = $order['prepay_id'];
     $msg['package'] = 'Sign=WXPay';
     $msg['noncestr'] = $order['nonce_str'];
     $msg['timestamp'] = time();
     //$this->json['sign'] = $order['sign'];
     //再次生成签名
     ksort($msg);
     //$string = $aa->ToUrlParams($this->json);
     $buff = "";
     foreach ($msg as $k => $v) {
         if ($k != "sign" && $v != "" && !is_array($v)) {
             $buff .= $k . "=" . $v . "&";
         }
     }
     $buff = trim($buff, "&");
     $string = $buff;
     //签名步骤二:在string后加入KEY
     $string = $string . "&key=" . WxPayConfig::KEY;
     //签名步骤三:MD5加密
     $string = md5($string);
     //签名步骤四:所有字符转为大写
     $result = strtoupper($string);
     $msg['sign'] = $result;
     //dump($msg);
     ajaxSucReturn($msg);
 }
Esempio n. 19
0
//①、获取用户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);
$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)
 */
?>

<html>
Esempio n. 20
0
 public function actionCompany()
 {
     try {
         $list = Yii::app()->user->orderlist;
         $date = Yii::app()->user->orderdate;
         $months = Yii::app()->user->ordermonths;
     } catch (Exception $e) {
         echo 'fail';
         die;
     }
     if (Yii::app()->user->isGuest) {
         $userId = Yii::app()->session['user']['id'];
     } else {
         $userId = Yii::app()->user->id;
     }
     $wechat = Yii::app()->params['partner']['wechat'];
     $jsapi = new WxJsPayHelper();
     $openid = $jsapi->GetOpenid();
     $this->bodyCss = 'orderDetail';
     $totalPrice = 0;
     foreach ($list as &$value) {
         $product = CompanyProduct::model()->findByAttributes(array('id' => $value['id']));
         $value['name'] = $product->name;
         $value['price'] = $product->price;
         $value['type'] = $product->type;
         $totalPrice = $totalPrice + $value['price'] * $value['num'];
     }
     $order = new COrder();
     $newOrder = $order->create(array('userId' => $userId, 'type' => 2, 'price' => $totalPrice, 'orderTime' => date('YmdHis'), 'hubId' => 1));
     $orderId = $newOrder['data']['orderId'];
     $endDate = date('Y-m-d', strtotime($date) + (date('t', strtotime($date)) - 1) * $months * 60 * 60 * 24);
     foreach ($list as $v) {
         $companyProduct = $order->createCompanyProduct(array('cproductId' => $v['id'], 'startDate' => $date, 'endDate' => $endDate, 'orderId' => $orderId, 'num' => $v['num']));
         Coding::makeCode(array('userId' => $userId, 'type' => $v['type'], 'startDate' => $date, 'endDate' => $endDate, 'times' => $v['num'], 'ordercompanyProductId' => $companyProduct['data']['id']));
     }
     $input = new WxPayUnifiedOrder();
     $input->SetBody('Company product');
     // $input->SetAttach(date('Ymd',$date));
     $input->SetOut_trade_no((string) $orderId);
     $input->SetTotal_fee($totalPrice / 100);
     $input->SetTime_start(date('YmdHis'));
     $input->SetTime_expire(Assist::getOrderExpireTime(time()));
     $input->SetProduct_id(1);
     $input->SetNotify_url('http://hubapp.livenaked.com' . $wechat['payment']['notify']);
     $input->SetTrade_type('JSAPI');
     $input->SetOpenid($openid);
     Yii::log(print_r($input->values, 1), CLogger::LEVEL_ERROR, 'input');
     $bill = WxPayApi::unifiedOrder($input);
     $jsApiParameters = $jsapi->GetJsApiParameters($bill);
     $this->render('company', array('list' => $list, 'date' => $date, 'months' => $months, 'totalPrice' => $totalPrice, 'jsparams' => $jsApiParameters));
 }
Esempio n. 21
0
 /**
  *
  */
 public function jsApiParametersGet_action($mpid, $order)
 {
     $user = $this->getUser($mpid);
     $order = $this->model('app\\merchant\\order')->byId($order);
     if (false === $order) {
         return new \ResponseError('订单不存在');
     }
     $products = array();
     $order->products = json_decode($order->products);
     foreach ($order->products as $prod) {
         $products[] = $prod->name;
     }
     $products = implode(',', $products);
     $notifyUrl = "http://" . $_SERVER['HTTP_HOST'];
     $notifyUrl .= "/rest/op/merchant/payok/notify";
     $tools = $this->model('mpproxy/WxPayJsApi');
     $wxPayConfig = new \WxPayConfig($mpid);
     $input = new \WxPayUnifiedOrder();
     $input->SetBody($products);
     $input->SetAttach("测试附加信息");
     $input->SetOut_trade_no($order->trade_no);
     $input->SetTotal_fee($order->order_total_price);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetGoods_tag("测试标签");
     $input->SetNotify_url($notifyUrl);
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($user->openid);
     $order = \WxPayApi::unifiedOrder($mpid, $input);
     if ($order['result_code'] === 'FAIL') {
         return new \ResponseError($order['err_code_des']);
     }
     $jsApiParameters = $tools->GetJsApiParameters($mpid, $order);
     //获取共享收货地址js函数参数
     $editAddress = $tools->GetEditAddressParameters($mpid);
     $rsp = array('jsApiParameters' => $jsApiParameters, 'editAddress' => $editAddress);
     return new \ResponseData($rsp);
 }
Esempio n. 22
0
 public function doMobileAjaxpay()
 {
     global $_GPC, $_W;
     load()->func('communication');
     $fromopenid = $_GPC['fromopenid'];
     $myopenid = $_W['openid'];
     $num = 1;
     $content = $_GPC['content'];
     include_once '../addons/beauty_zhongchou/WxPay.Api.php';
     $WxPayApi = new WxPayApi();
     $input = new WxPayUnifiedOrder();
     //				$key=$this->module['config']['apikey'];//商户支付秘钥(API秘钥)
     $key = 'xLeBESmggiQMGpba2ieADmRQDlDPmIL8';
     $account_info = pdo_fetch("select * from" . tablename('account_wechats') . "where uniacid={$_W['uniacid']}");
     //身份标识(appid)
     $appid = $account_info['key'];
     //$mchid=$this->module['config']['mchid'];//微信支付商户号(mchid)
     $mchid = '1239385202';
     $input->SetAppid($appid);
     $input->SetMch_id($mchid);
     $input->SetBody("test");
     $input->SetAttach("test");
     $input->SetOut_trade_no($mchid . date("YmdHis"));
     $input->SetTotal_fee($num);
     $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($myopenid);
     $result = $WxPayApi->unifiedOrder($input, 6, $key);
     //随机字符串
     $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
     $str = "";
     for ($i = 0; $i < 32; $i++) {
         $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
     }
     //签名
     $sign = $input->SetSign($key);
     $data = array();
     $data['pack'] = $result['prepay_id'];
     $data['appId'] = $appid;
     $data['timeStamp'] = TIMESTAMP;
     $data['nonceStr'] = $str;
     $data['signType'] = "MD5";
     $data['paySign'] = $sign;
     //生成订单
     //		$data2 = array(
     //			'uniacid' => $_W['uniacid'],
     //			'openid' => $myopenid,
     //			'ordersn' => date('Ymd').substr(time(), -5).substr(microtime(), 2, 5).sprintf('%02d', rand(0, 99)),
     //			'content'=>$content,
     //			'num' => $num,
     //			'status' => 0,//订单状态,-1取消状态,0普通状态,1为已付款,2为已发货,3为成功
     //			'fromopenid'=>$fromopenid,
     //			'content'=>
     //			'createtime' => TIMESTAMP
     //		);
     pdo_insert('beatuty_zhongchou_orders', $data2);
     $orderid = pdo_insertid();
     $order = pdo_fetch("SELECT * FROM " . tablename('beatuty_zhongchou_orders') . " WHERE id ={$orderid}");
     $params['tid'] = $order['ordersn'];
     $params['user'] = $_W['fans']['from_user'];
     $params['fee'] = $order['num'];
     $params['title'] = $_W['account']['name'];
     $params['ordersn'] = $order['ordersn'];
     $params['module'] = "beatuty_zhongchou";
     //转成json
     $dataall = array('data' => $data, 'params' => $params);
     return json_encode($dataall);
 }
 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]);
 }
Esempio n. 24
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);
  
  }
Esempio n. 25
0
 /**
  *
  * 按类型获取支付凭证
  * @param data
  */
 public static function getPayConfig($data)
 {
     $input = self::getUnifiedOrder($data);
     $config = WxPayApi::unifiedOrder($input);
     if ($config['return_code'] == 'FAIL') {
         throw new WxPayException($config['return_msg'], 1);
     }
     if ($data['trade_type'] = 'JSAPI') {
         $jsapi = new WxPayJsApiPay();
         $jsapi->SetAppid($config["appid"]);
         $jsapi->SetTimeStamp(strtotime($data['time_start']));
         $jsapi->SetNonceStr(WxPayApi::getNonceStr());
         $jsapi->SetPackage("prepay_id=" . $config['prepay_id']);
         $jsapi->SetSignType("MD5");
         $jsapi->SetPaySign($jsapi->MakeSign());
         $parameters = json_encode($jsapi->GetValues());
         return $parameters;
     } else {
         if ($data['trade_type'] = 'APP') {
             // TODO HBuilder
             // // 参与签名的字段名为appId,partnerId,prepayId,nonceStr,timeStamp,package。注意:package的值格式为Sign=WXPay
             // $time_stamp = time();
             // $pack   = 'Sign=WXPay';
             // //输出参数列表
             // $prePayParams =array();
             // $prePayParams['appid']      =$config['appid'];
             // $prePayParams['partnerid']  =$config['mch_id'];
             // $prePayParams['prepayid']   =$config['prepay_id'];
             // $prePayParams['noncestr']   =$config['nonce_str'];
             // $prePayParams['package']    =$pack;
             // $prePayParams['timestamp']  =$time_stamp;
             // $prePayParams['sign']       =$config['sign'];
             // return $prePayParams;
         }
     }
     return $config;
 }
Esempio n. 26
0
header('Access-Control-Allow-Origin: *');
header('Content-type: text/plain');
require_once "WxPay.Api.php";
require_once "WxPay.Data.php";
// 获取支付金额
$amount = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $amount = $_POST['total'];
} else {
    $amount = $_GET['total'];
}
$total = floatval($amount);
$total = round($total * 100);
// 将元转成分
if (empty($total)) {
    $total = 100;
}
// 商品名称
$subject = 'DCloud项目捐赠';
// 订单号,示例代码使用时间值作为唯一的订单ID号
$out_trade_no = date('YmdHis', time());
$unifiedOrder = new WxPayUnifiedOrder();
$unifiedOrder->SetBody($subject);
//商品或支付单简要描述
$unifiedOrder->SetOut_trade_no($out_trade_no);
$unifiedOrder->SetTotal_fee($total);
$unifiedOrder->SetTrade_type("APP");
$result = WxPayApi::unifiedOrder($unifiedOrder);
if (is_array($result)) {
    echo json_encode($result);
}
Esempio n. 27
0
 public function index()
 {
     //echo "one";
     $this->load->library('wxpayexception');
     //echo "two";
     $this->load->library('wxpayconfig');
     //echo "three";
     $this->load->library('wxpaydata');
     //echo "four";
     $this->load->library('wxpayapi');
     //echo "five";
     $this->load->library('wxpayjsapipay');
     //echo "six";
     //echo "1";
     /*
     WxPayConfig::$APPID = $this->config->get('wxpay_appid');
     	    WxPayConfig::$MCHID = $this->config->get('wxpay_mchid');
     	    WxPayConfig::$KEY = $this->config->get('wxpay_key');
     WxPayConfig::$APPSECRET = $this->config->get('wxpay_appsecret');
     WxPayConfig::$SSLCERT_PATH = DIR_SYSTEM.'helper/wxpay_key/apiclient_cert.pem';
     WxPayConfig::$SSLKEY_PATH = DIR_SYSTEM.'helper/wxpay_key/apiclient_key.pem';
     */
     //echo "2";
     $this->language->load('payment/wxpay');
     $data['button_confirm'] = $this->language->get('button_confirm');
     $this->load->model('checkout/order');
     $order_id = $this->session->data['order_id'];
     $order_info = $this->model_checkout_order->getOrder($order_id);
     $item_name = $this->config->get('config_name');
     $fullname = $order_info['payment_fullname'];
     $this->load->model('account/order');
     $shipping_cost = 0;
     $totals = $this->model_account_order->getOrderTotals($order_id);
     foreach ($totals as $total) {
         if ($total['title'] == 'shipping') {
             $shipping_cost = $total['value'];
         }
     }
     $notify_url = HTTPS_SERVER . 'catalog/controller/payment/wxpay_callback.php';
     $out_trade_no = $this->session->data['order_id'];
     $subject = $item_name . ' ' . $this->language->get('text_order') . ' ' . $order_id;
     $amount = $order_info['total'];
     $currency_value = $this->currency->getValue('CNY');
     $price = $amount * $currency_value;
     $price = number_format($price, 2, '.', '');
     $total_fee = $price * 100;
     //乘100去掉小数点,以传递整数给微信支付
     //$total_fee = 1;
     //echo "Total Fee: ".$total_fee."<br>";
     //echo "3";
     //①、获取用户openid
     $tools = new JsApiPay();
     //$openId = $tools->GetOpenid();
     $openId = $this->session->data['weixin_openid'];
     //echo "4<br>";
     //echo $openId;
     //②、统一下单
     $input = new WxPayUnifiedOrder();
     //echo "5";
     $input->SetBody($subject);
     $input->SetAttach("test by yang");
     $input->SetOut_trade_no($order_id);
     $input->SetTotal_fee($total_fee);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetGoods_tag("test goods tags");
     $input->SetNotify_url($notify_url);
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     //echo "6";
     $order = WxPayApi::unifiedOrder($input);
     //print_r($order);
     //echo "7";
     //echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>';
     //printf_info($order);
     $data['jsApiParameters'] = $tools->GetJsApiParameters($order);
     //echo "8";
     //获取共享收货地址js函数参数
     $data['editAddress'] = $tools->GetEditAddressParameters();
     //echo "9";
     $data['return_url'] = $this->url->link('checkout/success');
     $data['checkout_url'] = $this->url->link('checkout/checkout');
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/wxpay.tpl')) {
         return $this->load->view($this->config->get('config_template') . '/template/payment/wxpay.tpl', $data);
     } else {
         return $this->load->view('default/template/payment/wxpay.tpl', $data);
     }
 }
Esempio n. 28
0
        $input->SetTotal_fee($pay_toatal_price);
        // 订单支付总金额,整数,以分为单位
        //$input->SetTotal_fee(1);
        $input->SetTime_start(date("YmdHis"));
        // 订单生成时间,格式为yyyyMMddHHmmss
        $input->SetTime_expire(date("YmdHis", time() + Config::WX_ORDER_TIMEOUT));
        // 订单失效时间,格式为yyyyMMddHHmmss
        $input->SetGoods_tag(Config::WX_ORDER_TAG);
        // 设置商品标记
        $input->SetNotify_url(Config::API_NOTIFY_URL);
        // 接收微信支付异步通知回调地址
        $input->SetTrade_type("JSAPI");
        // 交易类型
        $input->SetOpenid($openId);
        // 微信用户的Openid
        $order = WxPayApi::unifiedOrder($input, Config::API_TIMEOUT, Config::API_NOTIFY_URL);
        // 创建预付订单
        $jsApiParameters = $tools->GetJsApiParameters($order);
        // 获取共享收货地址js函数参数
        //$editAddress = $tools->GetEditAddressParameters();
    } else {
        throw new Exception('order_info requrired,but empty be given');
    }
    //第四步:在支付成功回调通知中处理成功之后的事宜,见 notify.php
} catch (Exception $e) {
    Log::ERROR(sprintf('run exceptin:%s|file:%s|line:%s', $e->getMessage(), $e->getFile(), $e->getLine()));
}
?>
<!DOCTYPE html>
<html>
<head lang="zh">
 protected function create_order($user_id, $trade_type, $attach, $fee, $open_id = null)
 {
     // 商户号 + 用户id + uniqid生成的随机字符串
     $out_trade_no = WxPayConfig::MCHID . uniqid($user_id);
     // 需重置下当前时区,PHP配置文件不知为何不起作用
     //date_default_timezone_set('PRC');
     // 统一下单
     $input = new WxPayUnifiedOrder();
     $input->SetBody("挂号费");
     $input->SetAttach($attach);
     $input->SetOut_trade_no($out_trade_no);
     // 测试用1分钱
     $input->SetTotal_fee(1);
     $current_time = time();
     $start = date('YmdHis', $current_time);
     $expire = date('YmdHis', $current_time + 3600);
     // 下单时间:当前时间
     $input->SetTime_start($start);
     // 失效时间:测试用一个小时
     $input->SetTime_expire($expire);
     $input->SetGoods_tag("挂号费");
     $input->SetNotify_url("http://test.zerioi.com/pay/wxpay_notify");
     $input->SetTrade_type($trade_type);
     // JSAPI调用支付需设置open_id
     if ($open_id) {
         $input->SetOpenid($open_id);
     }
     $record = new WeixinPay();
     $record->trade_no = $out_trade_no;
     $record->trade_type = $trade_type;
     $record->time_start = $start;
     $record->time_expire = $expire;
     $record->user_id = $user_id;
     $record->open_id = $open_id;
     $record->attach = $attach;
     $record->total_fee = $fee;
     $record->status = 'UNFINISHED';
     if (!$record->save()) {
         throw new Exception("Could not save pay parameters");
     }
     return WxPayApi::unifiedOrder($input);
 }
Esempio n. 30
0
function joinwxinfo($body_arr)
{
    $resp = array();
    $order_no = $body_arr['order_no'];
    $randnum = rand(1000, 9999);
    //产生一个4位随机数
    $out_trade_no = $order_no;
    //. '-' . $randnum; //记录订单号+_+随机数
    //    $arr['device_info'] = isset($body_arr['client_ip'])?$body_arr['client_ip']:''; //客户端地址
    $input = new WxPayUnifiedOrder();
    $input->SetBody($out_trade_no);
    $input->SetOut_trade_no($out_trade_no);
    $input->SetTotal_fee(getfee($body_arr));
    //这里是微信,默认单位:分
    $time = time();
    $input->SetTime_start(date("YmdHis"), $time);
    $input->SetTime_expire(date("YmdHis", $time + 600));
    $input->SetNotify_url(_WXNOTIFYURL_ . 'pay/mobilepay/wxpay/interface/appnotify.php');
    $input->SetTrade_type("APP");
    //    $WxPayUnifiedOrder->SetAttach("test");
    //    $input->SetGoods_tag("test");
    //    $input->SetProduct_id("123456789");
    $retarr = WxPayApi::unifiedOrder($input);
    //返回数据解析为数组了
    if ($retarr['return_code'] == 'SUCCESS') {
        //成功
        $nostr = WxPayApi::getNonceStr();
        $resp['wx_app_id'] = $retarr['appid'];
        $resp['wx_partner_id'] = $retarr['mch_id'];
        $resp['wx_nonce'] = $nostr;
        //$retarr['nonce_str'];
        $resp['wx_timestamp'] = $time;
        //date("YmdHis");
        $retinput = new WxPayReplyData();
        if ($retarr['result_code'] == 'SUCCESS') {
            $resp['wx_prepay_id'] = $retarr['prepay_id'];
            $retinput->SetappId(WxPayConfig::APPID);
            //公众账号ID
            $retinput->SetnonceStr($nostr);
            //随机字符串
            $retinput->Setpackage('Sign=WXPay');
            $retinput->SetpartnerId($retarr['mch_id']);
            $retinput->SetprepayId($retarr['prepay_id']);
            $retinput->SettimeStamp($time);
            //
            $resp['wx_sign'] = $retinput->MakeSignSpecil();
        }
        $resp['wx_package'] = 'Sign=WXPay';
        //固定值
    } else {
        $resp = $retarr;
        $resp['status'] = 1046;
        $resp['desc'] = '失败';
    }
    return $resp;
}