コード例 #1
0
ファイル: Weixin.class.php プロジェクト: fkssei/pigcms10
 public function pay()
 {
     if (empty($this->pay_config['pay_weixin_appid']) || empty($this->pay_config['pay_weixin_mchid']) || empty($this->pay_config['pay_weixin_key'])) {
         return array('err_code' => 1, 'err_msg' => '微信支付缺少配置信息!请联系管理员处理或选择其他支付方式。');
     }
     if (empty($this->openid)) {
         return array('err_code' => 1, 'err_msg' => '没有获取到用户的微信资料,无法使用微信支付');
     }
     import('source.class.pay.Weixinnewpay.WxPayPubHelper');
     $jsApi = new JsApi_pub($this->pay_config['pay_weixin_appid'], $this->pay_config['pay_weixin_mchid'], $this->pay_config['pay_weixin_key']);
     $unifiedOrder = new UnifiedOrder_pub($this->pay_config['pay_weixin_appid'], $this->pay_config['pay_weixin_mchid'], $this->pay_config['pay_weixin_key']);
     $unifiedOrder->setParameter('openid', $this->openid);
     $unifiedOrder->setParameter('body', $this->order_info['order_no_txt']);
     $unifiedOrder->setParameter('out_trade_no', $this->order_info['trade_no']);
     $unifiedOrder->setParameter('total_fee', floatval($this->order_info['total'] * 100));
     $unifiedOrder->setParameter('notify_url', option('config.wap_site_url') . '/paynotice.php');
     $unifiedOrder->setParameter('trade_type', 'JSAPI');
     $unifiedOrder->setParameter('attach', 'weixin');
     $prepay_result = $unifiedOrder->getPrepayId();
     if ($prepay_result['return_code'] == 'FAIL') {
         return array('err_code' => 1, 'err_msg' => '没有获取微信支付的预支付ID,请重新发起支付!<br/><br/>微信支付错误返回:' . $prepay_result['return_msg']);
     }
     if ($prepay_result['err_code']) {
         return array('err_code' => 1, 'err_msg' => '没有获取微信支付的预支付ID,请重新发起支付!<br/><br/>微信支付错误返回:' . $prepay_result['err_code_des']);
     }
     $jsApi->setPrepayId($prepay_result['prepay_id']);
     return array('err_code' => 0, 'pay_data' => $jsApi->getParameters());
 }
コード例 #2
0
 public function test($order_id = '')
 {
     vendor('WxPayPubHelper.WxPayPubHelper');
     //使用jsapi接口
     $jsApi = new \JsApi_pub();
     //=========步骤1:网页授权获取用户openid============
     //通过code获得openid
     if (!isset($_GET['code'])) {
         //触发微信返回code码
         $url = $jsApi->createOauthUrlForCode(\WxPayConf_pub::JS_API_CALL_URL . __SELF__);
         Header("Location: {$url}");
     } else {
         //获取code码,以获取openid
         $code = $_GET['code'];
         $jsApi->setCode($code);
         $openid = $jsApi->getOpenId();
     }
     $unifiedOrder = new \UnifiedOrder_pub();
     $order_info = M('FxOrder')->find($order_id);
     $order_info['product_name'] = '中华聚宝分销商城';
     $unifiedOrder->setParameter("openid", $openid);
     //商品描述
     $unifiedOrder->setParameter("body", '中华聚宝分销商城共消费¥' . $order_info['price']);
     //商品描述
     //自定义订单号,此处仅作举例
     $timeStamp = time();
     $out_trade_no = \WxPayConf_pub::APPID . $timeStamp;
     $unifiedOrder->setParameter("out_trade_no", $order_id . '_' . mt_rand(100, 999));
     //商户订单号
     if ($openid == 'olEDawig2ZbRO2v2zBNoyxXB32SE' || $openid == 'olEDawtGeisOHSSa539SCY68xqNc') {
         $unifiedOrder->setParameter("total_fee", $order_info['price']);
         //总金额
     } else {
         $unifiedOrder->setParameter("total_fee", $order_info['price'] * 100);
         //总金额
     }
     $unifiedOrder->setParameter("notify_url", \WxPayConf_pub::NOTIFY_URL_FX);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     //非必填参数,商户可根据实际情况选填
     // $unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号
     // $unifiedOrder->setParameter("device_info","XXXX");//设备号
     // $unifiedOrder->setParameter("attach","附加数据");//附加数据
     // $unifiedOrder->setParameter("time_start","交易起始时间");//交易起始时间
     // $unifiedOrder->setParameter("time_expire","交易结束时间");//交易结束时间
     // $unifiedOrder->setParameter("goods_tag","商品标记");//商品标记
     $unifiedOrder->setParameter("product_id", $order_id);
     //商品ID
     $prepay_id = $unifiedOrder->getPrepayId();
     // print_r($unifiedOrder);
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $this->assign('jsApiParameters', $jsApiParameters);
     $this->assign('order_id', $order_id);
     $this->display();
 }
コード例 #3
0
 public function new_pay()
 {
     import('@.ORG.Weixinnewpay.WxPayPubHelper');
     //使用jsapi接口
     $jsApi = new JsApi_pub($this->payConfig['new_appid'], $this->payConfig['mchid'], $this->payConfig['key'], $this->payConfig['appsecret']);
     //获取订单信息
     $orderid = $_GET['single_orderid'];
     $payHandel = new payHandle($this->token, $_GET['from'], 'weixin');
     $orderInfo = $payHandel->beforePay($orderid);
     $price = $orderInfo['price'];
     //判断是否已经支付过
     if ($orderInfo['paid']) {
         exit('您已经支付过此次订单!');
     }
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $unifiedOrder = new UnifiedOrder_pub($this->payConfig['new_appid'], $this->payConfig['mchid'], $this->payConfig['key'], $this->payConfig['appsecret']);
     $unifiedOrder->setParameter("openid", $_GET['wecha_id']);
     //商品描述
     $unifiedOrder->setParameter("body", $orderid);
     //商品描述
     //自定义订单号,此处仅作举例
     $unifiedOrder->setParameter("out_trade_no", $orderid);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", $price * 100);
     //总金额
     if (strpos(CONF_PATH, 'DataPig')) {
         $noticeFileName = 'notice_datapig.php';
     } elseif (strpos(CONF_PATH, 'weimidata')) {
         $noticeFileName = 'notice_weimidata.php';
     } else {
         $noticeFileName = 'notice.php';
     }
     $unifiedOrder->setParameter("notify_url", C('site_url') . '/wxpay/' . $noticeFileName);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $unifiedOrder->setParameter("attach", 'token=' . $_GET['token'] . '&wecha_id=' . $_GET['wecha_id'] . '&from=' . $_GET['from']);
     //附加数据
     $prepay_id = $unifiedOrder->getPrepayId();
     if (empty($prepay_id)) {
         $this->error('没有获取到微信支付预支付ID,请管理员检查微信支付配置项!');
     }
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $this->assign('jsApiParameters', $jsApiParameters);
     $from = $_GET['from'];
     $from = $from ? $from : 'Groupon';
     $from = $from != 'groupon' ? $from : 'Groupon';
     $returnUrl = $this->siteUrl . '/index.php?g=Wap&m=' . $from . '&a=payReturn&nohandle=1&token=' . $_GET['token'] . '&wecha_id=' . $_GET['wecha_id'] . '&orderid=' . $orderid;
     $this->assign('returnUrl', $returnUrl);
     //$this->display();
     echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" /><meta name="apple-mobile-web-app-capable" content="yes" /><meta name="apple-mobile-web-app-status-bar-style" content="black" /><meta name="format-detection" content="telephone=no" /><link href="/tpl/Wap/default/common/css/style/css/hotels.css" rel="stylesheet" type="text/css" /><title>微信支付</title><script language="javascript">function callpay(){WeixinJSBridge.invoke("getBrandWCPayRequest",' . $jsApiParameters . ',function(res){WeixinJSBridge.log(res.err_msg);if(res.err_msg=="get_brand_wcpay_request:ok"){document.getElementById("payDom").style.display="none";document.getElementById("successDom").style.display="";setTimeout("window.location.href = \'' . $returnUrl . '\'",2000);}else{if(res.err_msg == "get_brand_wcpay_request:cancel"){var err_msg = "您取消了支付";}else if(res.err_msg == "get_brand_wcpay_request:fail"){var err_msg = "支付失败<br/>错误信息:"+res.err_desc;}else{var err_msg = res.err_msg +"<br/>"+res.err_desc;}document.getElementById("payDom").style.display="none";document.getElementById("failDom").style.display="";document.getElementById("failRt").innerHTML=err_msg;}});}</script></head><body style="padding-top:20px;"><style>.deploy_ctype_tip{z-index:1001;width:100%;text-align:center;position:fixed;top:50%;margin-top:-23px;left:0;}.deploy_ctype_tip p{display:inline-block;padding:13px 24px;border:solid #d6d482 1px;background:#f5f4c5;font-size:16px;color:#8f772f;line-height:18px;border-radius:3px;}</style><div id="payDom" class="cardexplain"><ul class="round"><li class="title mb"><span class="none">支付信息</span></li><li class="nob"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="kuang"><tr><th>金额</th><td>' . floatval($_GET['price']) . '元</td></tr></table></li></ul><div class="footReturn" style="text-align:center"><input type="button" style="margin:0 auto 20px auto;width:100%"  onclick="callpay()"  class="submit" value="点击进行微信支付" /></div></div><div id="failDom" style="display:none" class="cardexplain"><ul class="round"><li class="title mb"><span class="none">支付结果</span></li><li class="nob"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="kuang"><tr><th>支付失败</th><td><div id="failRt"></div></td></tr></table></li></ul><div class="footReturn" style="text-align:center"><input type="button" style="margin:0 auto 20px auto;width:100%"  onclick="callpay()"  class="submit" value="重新进行支付" /></div></div><div id="successDom" style="display:none" class="cardexplain"><ul class="round"><li class="title mb"><span class="none">支付成功</span></li><li class="nob"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="kuang"><tr><td>您已支付成功,页面正在跳转...</td></tr></table><div id="failRt"></div></li></ul></div></body></html>';
 }
コード例 #4
0
ファイル: weixin.php プロジェクト: seanguo166/yinoos
 /**
  * 生成支付代码
  * @param   array   $order      订单信息
  * @param   array   $payment    支付方式信息
  */
 function get_code($order, $payment)
 {
     $return_url = 'http://' . $_SERVER['HTTP_HOST'] . '/respond.php';
     define(APPID, $payment['appId']);
     // appid
     define(APPSECRET, $payment['appSecret']);
     // appSecret
     define(MCHID, $payment['partnerId']);
     define(KEY, $payment['partnerKey']);
     // 通加密串
     define(NOTIFY_URL, $return_url);
     // 成功回调url
     include_once "weixin/WxPayPubHelper.php";
     $selfUrl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
     if (!strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) {
         return $this->natpayHtml($order);
     }
     $jsApi = new JsApi_pub();
     if ($_SESSION['user_id']) {
         $openid = $GLOBALS['db']->getOne("select fake_id from " . $GLOBALS['ecs']->table('weixin_user') . " where ecuid='{$_SESSION['user_id']}'");
     }
     $openid = $openid ? $openid : $_SESSION['wx_openid'];
     if (!$openid) {
         if (!isset($_GET['code'])) {
             // 触发微信返回code码
             $url = $jsApi->createOauthUrlForCode($selfUrl);
             Header("Location: {$url}");
             exit;
         } else {
             // 获取code码,以获取openid
             $code = $_GET['code'];
             $jsApi->setCode($code);
             $openid = $jsApi->getOpenId();
             $_SESSION['wx_openid'] = $openid;
         }
     }
     $unifiedOrder = new UnifiedOrder_pub();
     // 设置统一支付接口参数
     $unifiedOrder->setParameter("openid", $openid);
     $unifiedOrder->setParameter("body", $order['order_sn']);
     $unifiedOrder->setParameter("out_trade_no", $order['order_id']);
     // 商户订单号
     $unifiedOrder->setParameter("total_fee", $order['order_amount'] * 100);
     // 总金额
     $unifiedOrder->setParameter("notify_url", NOTIFY_URL);
     // 通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     // 交易类型
     $prepay_id = $unifiedOrder->getPrepayId();
     $jsApi->setPrepayId($prepay_id);
     return $jsApi->getParameters();
 }
コード例 #5
0
ファイル: WxJsPayAction.class.php プロジェクト: wmk223/demotp
 public function index()
 {
     $this->isUserLogin();
     vendor('Weixinpay.WxPayPubHelper');
     //使用jsapi接口
     $jsApi = new \JsApi_pub();
     //=========步骤1:网页授权获取用户openid============
     //通过code获得openid
     $code = $_GET['code'];
     $jsApi->setCode($code);
     $openid = session('WST_USER')['wxId'];
     $pkey = session('WST_USER')["userId"] . "@" . $_SESSION["orderIds"];
     $time = time();
     $res = array('order_sn' => $time, 'order_amount' => $_SESSION['needPay']);
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $unifiedOrder = new \UnifiedOrder_pub();
     $total_fee = $res['order_amount'] * 100;
     //$total_fee = 1;
     $body = "订单支付{$res['order_sn']}";
     $unifiedOrder->setParameter("openid", "{$openid}");
     //用户标识
     $unifiedOrder->setParameter("body", $body);
     //商品描述
     //自定义订单号,此处仅作举例
     $out_trade_no = $res['order_sn'];
     $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
     //商户订单号
     $unifiedOrder->setParameter("total_fee", $total_fee);
     //总金额
     $unifiedOrder->setParameter("attach", "{$pkey}");
     //附加数据
     $unifiedOrder->setParameter("notify_url", C('WxPayConf_pub.NOTIFY_URL'));
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $unifiedOrder->SetParameter("input_charset", "UTF-8");
     //非必填参数,商户可根据实际情况选填
     $prepay_id = $unifiedOrder->getPrepayId();
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $wxconf = json_decode($jsApiParameters, true);
     if ($wxconf['package'] == 'prepay_id=') {
         $this->error('当前订单存在异常,不能使用支付');
     }
     $this->assign('res', $res);
     $this->assign('jsApiParameters', $jsApiParameters);
     $this->display('default/payment/wxjsapi/wxpay');
 }
コード例 #6
0
 function get_payform($order_info)
 {
     if (!defined('WXAPPID')) {
         $_SESSION['order_info'] = $order_info;
         define("WXAPPID", $this->_config['appid']);
         define("WXMCHID", $this->_config['mchid']);
         define("WXKEY", $this->_config['key']);
         define("WXAPPSECRET", $this->_config['appsecret']);
         define("WXCURL_TIMEOUT", 30);
         define('WXNOTIFY_URL', $this->_create_notify_url($order_info["order_id"], $order_info['payment_code']));
         define('WXJS_API_CALL_URL', $this->_create_notify_url($order_info["order_id"], $order_info['payment_code']));
         define('WXSSLCERT_PATH', ROOT_PATH . '/data/cacert/1/apiclient_cert.pem');
         define('WXSSLKEY_PATH', ROOT_PATH . '/data/cacert/1/apiclient_key.pem');
     }
     require_once dirname(__FILE__) . "/WxPayPubHelper/WxPayPubHelper.php";
     $unifiedOrder = new UnifiedOrder_pub();
     $jsApi = new JsApi_pub();
     if (!isset($_GET['code'])) {
         $baseUrl = urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']);
         //触发微信返回code码
         $urll = $jsApi->createOauthUrlForCode($baseUrl);
         //echo $url;
         Header("Location: {$urll}");
     } else {
         //获取code码,以获取openid
         $code = $_GET['code'];
         $jsApi->setCode($code);
         $openid = $jsApi->getOpenid();
     }
     $out_trade_no = $this->_get_trade_sn($order_info);
     $_SESSION['out_trade_on'] = $out_trade_no;
     $unifiedOrder->setParameter("body", $out_trade_no);
     //商品描述
     $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
     //商户订单号
     $unifiedOrder->setParameter("attach", $order_info['order_id']);
     //商户支付日志
     $unifiedOrder->setParameter("total_fee", strval(intval($order_info['order_amount'] * 100)));
     //总金额
     $unifiedOrder->setParameter("notify_url", WXNOTIFY_URL);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $unifiedOrder->setParameter("openid", $openid);
     $jsApi->prepay_id = $unifiedOrder->getPrepayId();
     $unifiedOrderResult = $jsApi->getParameters();
     return $unifiedOrderResult;
 }
コード例 #7
0
ファイル: Weixin.class.php プロジェクト: belerweb/pigcms
 public function mobile_pay()
 {
     import('@.ORG.pay.Weixinnewpay.WxPayPubHelper');
     //使用jsapi接口
     $jsApi = new JsApi_pub($this->pay_config['pay_weixin_appid'], $this->pay_config['pay_weixin_mchid'], $this->pay_config['pay_weixin_key'], $this->pay_config['pay_weixin_appsecret']);
     //使用统一支付接口
     $unifiedOrder = new UnifiedOrder_pub($this->pay_config['pay_weixin_appid'], $this->pay_config['pay_weixin_mchid'], $this->pay_config['pay_weixin_key'], $this->pay_config['pay_weixin_appsecret']);
     $unifiedOrder->setParameter("openid", $_SESSION['openid']);
     //用户微信唯一标识
     $unifiedOrder->setParameter("body", $this->order_info['order_name'] . '_' . $this->order_info['order_num']);
     //商品描述
     //自定义订单号,此处仅作举例
     $unifiedOrder->setParameter("out_trade_no", $this->order_info['order_type'] . '_' . $this->order_info['order_id']);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", floatval($this->pay_money * 100));
     //总金额
     $unifiedOrder->setParameter("notify_url", C('config.site_url') . '/source/wap_weixin_notice.php');
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $unifiedOrder->setParameter("attach", 'weixin');
     //附加数据
     $prepay_result = $unifiedOrder->getPrepayId();
     if ($prepay_result['return_code'] == 'FAIL') {
         return array('error' => 1, 'msg' => '没有获取微信支付的预支付ID,请重新发起支付!微信支付错误返回:' . $prepay_result['return_msg']);
     }
     if ($prepay_result['err_code']) {
         return array('error' => 1, 'msg' => '没有获取微信支付的预支付ID,请重新发起支付!<br/><br/>微信支付错误返回:' . $prepay_result['err_code_des']);
     }
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_result['prepay_id']);
     return array('error' => 0, 'weixin_param' => $jsApi->getParameters());
 }
コード例 #8
0
 private function _jsDirect($order)
 {
     if (!isset($order['open_id']) || empty($order['open_id'])) {
         throw new PayException(ErrCode::ERR_GATEWAY_FAIL, '缺少参数open_id');
     }
     $config = $this->getConfig($order);
     $order['trade_type'] = 'JSAPI';
     $unifiedOrder = $this->_unifiedOrder($order);
     $prepayId = $unifiedOrder->getPrepayId();
     if (!$prepayId) {
         throw new PayException(ErrCode::ERR_GATEWAY_FAIL, '获取prepayId失败');
     }
     $jsApi = new \JsApi_pub($config);
     $jsApi->setPrepayId($prepayId);
     return $jsApi->getParameters();
 }
コード例 #9
0
ファイル: BCWXPay.php プロジェクト: rockylo/beecloud-php
 public static function getOpenID(array $data)
 {
     //使用jsapi接口
     $jsApi = new JsApi_pub();
     //=========步骤1:网页授权获取用户openid============
     //通过code获得openid
     if (!isset($data['code'])) {
         //触发微信返回code码
         $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL);
         Header("Location: {$url}");
     } else {
         //获取code码,以获取openid
         $code = $data['code'];
         $jsApi->setCode($code);
         $openid = $jsApi->getOpenId();
         return $openid;
     }
 }
コード例 #10
0
ファイル: wxpay_web.class.php プロジェクト: ping199143/1ydb
 public function config($config = null)
 {
     if (empty($_SERVER['HTTP_USER_AGENT']) || strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === false && strpos($_SERVER['HTTP_USER_AGENT'], 'Windows Phone') === false) {
         header('Location: ' . WEB_PATH . '/pay/wxpay_web_url/payinfo/nowechat');
         die;
     }
     include_once dirname(__FILE__) . "/wxpay/WxPayPubHelper.php";
     if (empty($config['pay_type_data'])) {
         $this->db = System::load_sys_class('model');
         $pay = $this->db->GetOne("SELECT * from `@#_pay` where `pay_class` = 'wxpay_web'");
         $config['pay_type_data'] = unserialize($pay['pay_key']);
     }
     WxPayConf_pub::$APPID = $config['pay_type_data']['APPID']['val'];
     WxPayConf_pub::$MCHID = $config['pay_type_data']['MCHID']['val'];
     WxPayConf_pub::$KEY = $config['pay_type_data']['KEY']['val'];
     WxPayConf_pub::$APPSECRET = $config['pay_type_data']['APPSECRET']['val'];
     $jsApi = new JsApi_pub();
     if (!isset($_GET['code'])) {
         $url = G_WEB_PATH . '/index.php/pay/wxpay_web_url/?money=' . $config['money'] . '&out_trade_no=' . $config['code'];
         $url = $jsApi->createOauthUrlForCode(urlencode($url));
         header("Location: {$url}");
         die;
     } else {
         $jsApi->setCode($_GET['code']);
         $openid = $jsApi->getOpenId();
     }
     //		var_dump($_GET);
     //		echo $openid;die;
     WxPayConf_pub::$SSLCERT_PATH = dirname(__FILE__) . '/cacert/apiclient_cert.pem';
     WxPayConf_pub::$SSLKEY_PATH = dirname(__FILE__) . '/cacert/apiclient_key.pem';
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $unifiedOrder = new UnifiedOrder_pub();
     //设置统一支付接口参数
     //设置必填参数
     //appid已填,商户无需重复填写
     //mch_id已填,商户无需重复填写
     //noncestr已填,商户无需重复填写
     //spbill_create_ip已填,商户无需重复填写
     //sign已填,商户无需重复填写
     $unifiedOrder->setParameter("openid", $openid);
     $unifiedOrder->setParameter("body", "购买商品");
     //商品描述
     $unifiedOrder->setParameter("out_trade_no", $config['code']);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", $config['money'] * 100);
     //总金额
     $unifiedOrder->setParameter("notify_url", $config['NotifyUrl']);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $prepay_id = $unifiedOrder->getPrepayId();
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     include 'wxpay_web.html.php';
 }
コード例 #11
0
 private function getPayParams($orderNo)
 {
     $userInfo = session('userInfo');
     if (!$userInfo) {
         return false;
     }
     $orderInfo = $this->getOrderInfoByNo($orderNo);
     if (!$orderInfo && !$orderInfo['tmp']) {
         return;
     }
     $totalPay = ((int) $orderInfo['price'] + (int) $orderInfo['expressPrice']) * 100;
     $userInfo = $this->getUserNewInfo($userInfo['id']);
     Vendor('WxPayPubHelper.WxPayPubHelper');
     //使用jsapi接口
     $jsApi = new \JsApi_pub();
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $unifiedOrder = new \UnifiedOrder_pub();
     //设置统一支付接口参数
     //设置必填参数
     //appid已填,商户无需重复填写
     //mch_id已填,商户无需重复填写
     //noncestr已填,商户无需重复填写
     //spbill_create_ip已填,商户无需重复填写
     //sign已填,商户无需重复填写
     $unifiedOrder->setParameter("openid", $userInfo['openId']);
     //商品描述
     $unifiedOrder->setParameter("body", "蒂罗尔曲奇商城订单");
     //商品描述
     //自定义订单号,此处仅作举例
     $timeStamp = time();
     $out_trade_no = \WxPayConf_pub::APPID . "{$timeStamp}";
     $unifiedOrder->setParameter("out_trade_no", $orderInfo['orderNo']);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", "{$totalPay}");
     //总金额
     $unifiedOrder->setParameter("notify_url", "http://www.tyrolland.cn/Weixin/Pay/notify");
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $unifiedOrder->setParameter("attach", "goods");
     //交易类型
     $prepay_id = $unifiedOrder->getPrepayId();
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     return json_decode($jsApiParameters, true);
 }
コード例 #12
0
ファイル: mb_payment.php プロジェクト: wangjiang988/ukshop
    function wxpayOp()
    {
        $model = Model('mb_payment');
        $params = array('payment_code' => 'wxpay');
        $pay = $model->get_payment_info($params);
        $rt = unserialize($pay['payment_config']);
        $payconf = array('appid' => $rt['wxpay_appid'], 'appsecret' => $rt['wxpay_appsecret'], 'apikey' => $rt['wxpay_key'], 'mch_id' => $rt['wxpay_mch_id']);
        include_once BASE_PATH . DS . 'api' . DS . "wxpay/WxPayApi.php";
        //使用jsapi接口
        $jsApi = new JsApi_pub($payconf);
        //=========步骤1:网页授权获取用户openid============
        //通过code获得openid
        if (isset($_SESSION['wx_openid']) && $_SESSION['wx_openid']) {
            $openid = trim($_SESSION['wx_openid']);
        } else {
            if (!isset($_GET['code'])) {
                $redirect_uri = SHOP_SITE_URL . '/index.php?act=mb_payment&op=wxpay&pay_sn=' . $_GET['pay_sn'];
                //触发微信返回code码
                $url = $jsApi->createOauthUrlForCode(urlencode($redirect_uri));
                Header("Location: {$url}");
            } else {
                //获取code码,以获取openid
                $code = $_GET['code'];
                $jsApi->setCode($code);
                $openid = $jsApi->getOpenId();
                $_SESSION['wx_openid'] = $openid;
            }
        }
        $notify_url = 'http://' . $_SERVER['SERVER_NAME'] . '/wxnotify.php';
        //=========步骤2:使用统一支付接口,获取prepay_id============
        //使用统一支付接口
        $unifiedOrder = new UnifiedOrder_pub($payconf);
        //get order info
        $model = Model('mb_payment');
        $condition['pay_sn'] = $_GET['pay_sn'];
        $condition['order_state'] = ORDER_STATE_NEW;
        $order_list = $model->get_order_detail($condition);
        $total_amount = 0;
        $shipping_fee = 0;
        $order_amount = 0;
        $goods_desc = '';
        $order_sn = '';
        foreach ($order_list as $row) {
            $order_amount = $row['order_amount'];
            $shipping_fee = $row['shipping_fee'];
            $goods_desc .= $row['goods_name'];
            $order_sn = $row['order_sn'];
        }
        $goods_desc = $this->my_cus_substr($goods_desc, 20);
        $total_amount = (int) ($shipping_fee * 100 + $order_amount * 100);
        //设置统一支付接口参数
        //设置必填参数
        //appid已填,商户无需重复填写
        //mch_id已填,商户无需重复填写
        //noncestr已填,商户无需重复填写
        //spbill_create_ip已填,商户无需重复填写
        //sign已填,商户无需重复填写
        $unifiedOrder->setParameter("openid", "{$openid}");
        //商品描述
        $unifiedOrder->setParameter("body", "{$goods_desc}");
        //商品描述
        $unifiedOrder->setParameter("out_trade_no", "{$order_sn}");
        //商户订单号
        $unifiedOrder->setParameter("total_fee", "{$total_amount}");
        //总金额
        $unifiedOrder->setParameter("notify_url", $notify_url);
        //通知地址
        $unifiedOrder->setParameter("trade_type", "JSAPI");
        //交易类型
        //非必填参数,商户可根据实际情况选填
        //$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();
        //=========步骤3:使用jsapi调起支付============
        $jsApi->setPrepayId($prepay_id);
        $jsApiParameters = $jsApi->getParameters();
        $redirect = SHOP_SITE_URL . '/index.php?act=wap_member_order';
        echo <<<EOF
\t\t\t<html>
\t\t\t\t<head>
\t\t\t\t    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
\t\t\t\t    <title>微信安全支付</title>
\t\t\t\t
\t\t\t\t\t<script type="text/javascript">
\t\t\t\t
\t\t\t\t\t\t//调用微信JS api 支付
\t\t\t\t\t\tfunction jsApiCall()
\t\t\t\t\t\t{
\t\t\t\t\t\t\tWeixinJSBridge.invoke(
\t\t\t\t\t\t\t\t'getBrandWCPayRequest',
\t\t\t\t\t\t\t\t{$jsApiParameters},
\t\t\t\t\t\t\t\tfunction(res){
\t\t\t\t\t\t\t\t\t//alert(res.err_msg);
\t\t\t\t\t\t\t\t\twindow.location.href = '{$redirect}';
\t\t\t\t\t\t\t\t}
\t\t\t\t\t\t\t);
\t\t\t\t\t\t}
\t\t\t\t
\t\t\t\t\t\tfunction callpay()
\t\t\t\t\t\t{
\t\t\t\t\t\t\tif (typeof WeixinJSBridge == "undefined"){
\t\t\t\t\t\t\t    if( document.addEventListener ){
\t\t\t\t\t\t\t        document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
\t\t\t\t\t\t\t    }else if (document.attachEvent){
\t\t\t\t\t\t\t        document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
\t\t\t\t\t\t\t        document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
\t\t\t\t\t\t\t    }
\t\t\t\t\t\t\t}else{
\t\t\t\t\t\t\t    jsApiCall();
\t\t\t\t\t\t\t}
\t\t\t\t\t\t}
\t\t\t\t\t</script>
\t\t\t\t</head>
\t\t\t\t<body style="font-size:12px" onLoad="callpay()"></body>
\t\t\t\t</html>
EOF;
    }
コード例 #13
0
ファイル: wechat.php プロジェクト: snamper/CI_xiaoshuhaochi
 function get_uid($return = '')
 {
     $user_agent = $_SERVER['HTTP_USER_AGENT'];
     if (strpos($user_agent, 'Mobile')) {
         if (strpos($user_agent, 'MicroMessenger') === false) {
             header("Content-type: text/html; charset=utf-8");
             echo "<script>alert('请在您的微信里关注公众号“小树好吃”并下单!')</script>";
             exit;
         }
     }
     $user_cookie = isset($_COOKIE['user_cookie_wechat']) ? $_COOKIE['user_cookie_wechat'] : '';
     //error_log(print_r($user_cookie,true),3,'/data/www/cookie.txt');
     if (!empty($user_cookie)) {
         $user_cookie = unserialize($user_cookie);
         return $user_cookie;
     } else {
         //调用授权页面
         require_once APPPATH . 'libraries/wechat/WxPayPubHelper.php';
         //使用jsapi接口
         $wechat_config_temp = $this->tickets->select('payment', array('name' => 'wechat'));
         $weipay = $wechat_config_temp[0];
         $jsApi = new JsApi_pub($weipay->app_id, $weipay->payname, $weipay->partner_key, $weipay->app_secret);
         //=========步骤1:网页授权获取用户openid============
         //通过code获得openid
         if (!isset($_GET['code'])) {
             //触发微信返回code码
             $url = $jsApi->createOauthUrlForCode(urlencode(base_url() . 'index.php?c=wechat&m=get_uid&return=' . $return));
             Header("Location: {$url}");
             exit;
         }
         //获取code码,以获取openid
         $code = $_GET['code'];
         $return = $_GET['return'];
         $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $weipay->app_id . "&secret=" . $weipay->app_secret . "&code=" . $code . "&grant_type=authorization_code";
         $result = $this->_curl_get_contents($url, 100);
         $result = json_decode($result);
         //
         //error_log(print_r($result,true),3,'/data/www/result.txt');
         if ($result->openid) {
             $user_temp = $this->tickets->select('users', array('tu_username' => $result->openid));
             if ($user_temp) {
                 $tem_uid = $user_temp[0]->tu_id;
             } else {
                 $tem_uid = $this->_register_wechat_user($result);
             }
         } else {
             $tem_uid = $this->_register_wechat_user($result);
         }
         $temp_user = $this->tickets->select('users', array('tu_id' => $tem_uid));
         $user = $temp_user[0];
         setcookie('user_cookie_wechat', serialize($user), time() + 3600 * 24 * 30, '/', "xiaoshuhaochi.com");
         return $user;
         //redirect($return.'/1');
     }
 }
コード例 #14
0
ファイル: js_api_call.php プロジェクト: show123456/taiyou
//******************获取订单信息
include_once "../../includes/config.inc.php";
$orderTable = D('sub_cz');
$oid = $_GET['oid'];
//订单号
$czArr = explode('_', $oid);
$id = $czArr[1];
if (!$id) {
    die("<script>alert('传递参数丢失');</script>");
}
$orderRow = $orderTable->find($id);
$orderfee = $orderRow['money'];
//单位为元
include_once "../weixinPay/WxPayPubHelper.php";
//使用jsapi接口
$jsApi = new JsApi_pub();
//=========步骤1:网页授权获取用户openid============
//通过code获得openid
//当前登录用户信息
$userRow = D('sub_user')->find($_SESSION['tyuser']['id']);
$openid = $userRow['fromuser'];
if (!$openid) {
    if (!isset($_GET['code'])) {
        //******************组装链接所带参数
        $returnPayUrl = urlencode(WxPayConf_pub::JS_API_CALL_URL . "czpay/js_api_call.php?oid=" . $oid);
        //触发微信返回code码
        $url = $jsApi->createOauthUrlForCode($returnPayUrl);
        Header("Location: {$url}");
    } else {
        //获取code码,以获取openid
        $code = $_GET['code'];
コード例 #15
0
 public function get_payment_code($payment_notice_id)
 {
     $payment_notice = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment_notice where id = " . $payment_notice_id);
     $order_sn = $payment_notice['notice_sn'];
     $money = round($payment_notice['money'], 2);
     $payment_info = $GLOBALS['db']->getRow("select id,config,logo from " . DB_PREFIX . "payment where id=" . intval($payment_notice['payment_id']));
     $payment_info['config'] = unserialize($payment_info['config']);
     $wx_config = $payment_info['config'];
     $sql = "select name " . "from " . DB_PREFIX . "deal " . "where id =" . intval($payment_notice['deal_id']);
     $title_name = $GLOBALS['db']->getOne($sql);
     if (!$payment_notice['order_id']) {
         $title_name = '充值';
     }
     $subject = $order_sn;
     include APP_ROOT_PATH . "system/payment/Wxjspay/WxPayPubHelper.php";
     // 		$data_notify_url = get_domain().APP_ROOT.'/wx_web/yjwap_response.php';
     //		$data_return_url = get_domain().APP_ROOT.'/wx_web/yjwap_notify.php';
     //
     //		$data_notify_url = str_replace("/sjmapi", "", $data_notify_url);
     //		$data_notify_url = str_replace("/mapi", "", $data_notify_url);
     //		$data_notify_url = str_replace("/wap", "", $data_notify_url);
     $data_return_url = str_replace("/sjmapi", "", $data_return_url);
     $data_return_url = str_replace("/mapi", "", $data_return_url);
     $data_return_url = str_replace("/wap", "", $data_return_url);
     $notify_url = get_domain() . REAL_APP_ROOT . "/wxpay_web/notify_url.php?order_id=" . intval($payment_notice['order_id']) . "&out_trade_no=" . $order_sn;
     //."&out_trade_no={$data.walipay.out_trade_no}";
     $order_id = $order_sn;
     //网页支付的订单在订单有效期内可以进行多次支付请求,但是需要注意的是每次请求的业务参数都要一致,交易时间也要保持一致。否则会报错“订单与已存在的订单信息不符”
     $return['notify_url'] = url_wap("cart#wx_jspay", array("id" => $payment_notice_id));
     $money_fen = intval($money * 100);
     if ($wx_config['type'] == 'V2') {
         require_once APP_ROOT_PATH . 'system/extend/ip.php';
         $iplocation = new iplocate();
         $user_ip = $iplocation->getIP();
         $unifiedOrder = new UnifiedOrder_pub();
         $unifiedOrder->update_config($wx_config['appid'], $wx_config['appsecret'], $wx_config['mchid'], $wx_config['partnerid'], $wx_config['partnerkey'], $wx_config['key'], $wx_config['sslcert'], $wx_config['sslkey']);
         $unifiedOrder->setParameter("input_charset", "GBK");
         $unifiedOrder->setParameter("bank_type", "WX");
         $unifiedOrder->setParameter("body", $title_name);
         $unifiedOrder->setParameter("partner", $wx_config['partnerid']);
         //$unifiedOrder->setParameter("out_trade_no", $unifiedOrder->create_noncestr());
         $unifiedOrder->setParameter("out_trade_no", $order_sn);
         $unifiedOrder->setParameter("total_fee", "{$money_fen}");
         $unifiedOrder->setParameter("fee_type", "0");
         $unifiedOrder->setParameter("notify_url", $notify_url);
         $unifiedOrder->setParameter("spbill_create_ip", $user_ip);
         $unifiedOrder->setParameter("input_charset", "GBK");
         $jsApiParameters = $unifiedOrder->create_biz_package();
     } elseif ($wx_config['type'] == 'V3' || $wx_config['type'] == 'V4') {
         $jsApi = new JsApi_pub();
         $jsApi->update_config($wx_config['appid'], $wx_config['appsecret'], $wx_config['mchid'], $wx_config['partnerid'], $wx_config['partnerkey'], $wx_config['key'], $wx_config['sslcert'], $wx_config['sslkey']);
         if (!isset($_GET['code'])) {
             //触发微信返回code码
             $url = $jsApi->createOauthUrlForCode(urlencode(get_domain() . $return['notify_url']));
             Header("Location: {$url}");
             $return['notify_url'] = $url;
             return $return;
         } else {
             //获取code码,以获取openid
             $code = $_GET['code'];
             $jsApi->setCode($code);
             $openid = $jsApi->getOpenId();
         }
         $unifiedOrder = new UnifiedOrder_pub();
         $unifiedOrder->update_config($wx_config['appid'], $wx_config['appsecret'], $wx_config['mchid'], $wx_config['partnerid'], $wx_config['partnerkey'], $wx_config['key'], $wx_config['sslcert'], $wx_config['sslkey']);
         $unifiedOrder->setParameter("openid", "{$openid}");
         //商品描述
         $unifiedOrder->setParameter("body", iconv_substr($title_name, 0, 50, 'UTF-8'));
         //商品描述
         $timeStamp = NOW_TIME;
         $unifiedOrder->setParameter("out_trade_no", "{$order_sn}");
         //商户订单号
         $unifiedOrder->setParameter("total_fee", $money_fen);
         //总金额
         $unifiedOrder->setParameter("notify_url", $notify_url);
         //通知地址
         $unifiedOrder->setParameter("trade_type", "JSAPI");
         //交易类型
         $prepay_id = $unifiedOrder->getPrepayId();
         //=========步骤3:使用jsapi调起支付============
         $jsApi->setPrepayId($prepay_id);
         $jsApiParameters = $jsApi->getParameters($wx_config['type']);
         if ($wx_config['type'] == 'V4') {
             $jsApiParameters = str_replace('deal_url', url_wap("deal#index", array('id' => $payment_notice['deal_id'])), $jsApiParameters);
         }
     }
     $return['parameters'] = $jsApiParameters;
     //echo $jsApiParameters;
     return $return;
 }
コード例 #16
0
ファイル: UserAction.class.php プロジェクト: lz1988/lejing
 public function member_recharge_pay()
 {
     //$cardcode = str_pad(mt_rand(0, 99999999), 8, '0', STR_PAD_RIGHT);
     /**
      * JS_API支付demo
      * ====================================================
      * 在微信浏览器里面打开H5网页中执行JS调起支付。接口输入输出数据格式为JSON。
      * 成功调起支付需要三个步骤:
      * 步骤1:网页授权获取用户openid
      * 步骤2:使用统一支付接口,获取prepay_id
      * 步骤3:使用jsapi调起支付
      */
     //include_once("../WxPayPubHelper/WxPayPubHelper.php");
     //include_once("../WxPayPubHelper/WxPayPubHelper.php");
     import('@.ORG.wxpay.WxPayPubHelper.WxPayPubHelper');
     //使用jsapi接口
     $jsApi = new JsApi_pub();
     //=========步骤1:网页授权获取用户openid============
     //通过code获得openid
     if (!isset($_GET['code'])) {
         //触发微信返回code码
         $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL_RECHARGE);
         Header("Location: {$url}");
     } else {
         //获取code码,以获取openid
         $code = $_GET['code'];
         $jsApi->setCode($code);
         $openid = $jsApi->getOpenId();
     }
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $unifiedOrder = new UnifiedOrder_pub();
     //取出当前订单的充值信息
     $user_recharge = M("user_recharge");
     $result = $user_recharge->where('order_recharge_sn = "' . $_SESSION['order_recharge_sn'] . '"')->find();
     $charge_remark = "充值:" . int($result['amount']);
     $unifiedOrder->setParameter("openid", "{$openid}");
     //openid
     $unifiedOrder->setParameter("body", $charge_remark);
     //商品描述
     //自定义订单号,此处仅作举例
     $timeStamp = time();
     $out_trade_no = WxPayConf_pub::APPID . "{$timeStamp}";
     $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
     //商户订单号
     $unifiedOrder->setParameter("total_fee", 0.1 * 100);
     //总金额
     $unifiedOrder->setParameter("notify_url", WxPayConf_pub::NOTIFY_URL_RECHARGE . "/order_recharge_sn/{$_SESSION['order_recharge_sn']}");
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $prepay_id = $unifiedOrder->getPrepayId();
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $this->assign('jsApiParameters', $jsApiParameters);
     $this->display();
 }
コード例 #17
0
ファイル: wxpay.php プロジェクト: shiruolin/hzzshop
 function get_code2($order, $payment)
 {
     //$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['share_pay_type'] > 0) {
         $returnrul = "share_pay.php?act=success&id=" . $order["order_id"];
     } else {
         if ($order['extension_code'] == 'team_goods') {
             $returnrul = $conf->successurl . $order["order_id"] . "&team=1";
         } else {
             $returnrul = $conf->successurl . $order["order_id"];
         }
     }
     //var_dump($returnrul);
     //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");
     //交易类型
     // $unifiedOrder->setParameter("body","商品");
     //    if(!empty($order['goods_name'])){
     //	    $unifiedOrder->setParameter("body",  mb_strlen($order['goods_name'],"utf-8")>20 ? mb_substr($order['goods_name'],0,20,'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();
     return array('jsApiParameters' => json_decode($jsApiParameters, true), 'returnrul' => $returnrul);
     //return $pay_online;
 }
コード例 #18
0
ファイル: WeixinAction.class.php プロジェクト: kevicki/pig
	public function new_pay()
	{
		$orderid = $_GET['single_orderid'];
		$payHandel = new payHandle($this->token, $_GET['from'], 'weixin');
		$orderInfo = $payHandel->beforePay($orderid);
		$price = $orderInfo['price'];
		$this->assign('price', $price);

		if ($orderInfo['paid']) {
			$returnUrl = $this->siteUrl . '/index.php?g=Wap&m=' . $_GET['from'] . '&a=payReturn&nohandle=1&token=' . $_GET['token'] . '&wecha_id=' . $_GET['wecha_id'] . '&orderid=' . $orderid;
			$this->redirect($returnUrl);
			exit();
		}

		if ($this->_issystem) {
			$url = $this->code($orderid, $price);

			if (!is_string($url)) {
				$this->error($url['msg']);
			}

			$this->assign('url', urlencode($url));
		}
		else {
			import('@.ORG.Weixinnewpay.WxPayPubHelper');
			$jsApi = new JsApi_pub($this->payConfig['new_appid'], $this->payConfig['mchid'], $this->payConfig['key'], $this->payConfig['appsecret']);
			$unifiedOrder = new UnifiedOrder_pub($this->payConfig['new_appid'], $this->payConfig['mchid'], $this->payConfig['key'], $this->payConfig['appsecret']);
			$unifiedOrder->setParameter('openid', $this->wecha_id);
			$unifiedOrder->setParameter('body', $orderid);
			$unifiedOrder->setParameter('out_trade_no', $orderid);
			$unifiedOrder->setParameter('total_fee', $price * 100);

			if (strpos(CONF_PATH, 'DataPig')) {
				$noticeFileName = 'notice_datapig.php';
			}
			else if (strpos(CONF_PATH, 'PigData')) {
				$noticeFileName = 'notice_pigdata.php';
			}
			else {
				$noticeFileName = 'notice.php';
			}

			$unifiedOrder->setParameter('notify_url', $this->siteUrl . '/wxpay/' . $noticeFileName);
			$unifiedOrder->setParameter('trade_type', 'JSAPI');
			$unifiedOrder->setParameter('attach', 'token=' . $_GET['token'] . '&wecha_id=' . $_GET['wecha_id'] . '&from=' . $_GET['from']);
			$prepay_id = $unifiedOrder->getPrepayId();

			if (empty($prepay_id)) {
				$this->error('没有获取到微信支付预支付ID,请管理员检查微信支付配置项!');
			}

			$jsApi->setPrepayId($prepay_id);
			$jsApiParameters = $jsApi->getParameters();
			$this->assign('jsApiParameters', $jsApiParameters);
		}

		$from = $_GET['from'];
		$from = ($from ? $from : 'Groupon');
		$from = ($from != 'groupon' ? $from : 'Groupon');
		$returnUrl = $this->siteUrl . '/index.php?g=Wap&m=' . $from . '&a=payReturn&nohandle=1&token=' . $_GET['token'] . '&wecha_id=' . $_GET['wecha_id'] . '&orderid=' . $orderid;
		$this->assign('returnUrl', $returnUrl);
		$message = '';
		$message .= '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" /><meta name="apple-mobile-web-app-capable" content="yes" /><meta name="apple-mobile-web-app-status-bar-style" content="black" /><meta name="format-detection" content="telephone=no" /><link href="/tpl/Wap/default/common/css/style/css/hotels.css" rel="stylesheet" type="text/css" /><title>微信支付</title>';

		if (empty($this->_issystem)) {
			$message .= '<script language="javascript">function callpay(){WeixinJSBridge.invoke("getBrandWCPayRequest",' . $jsApiParameters . ',function(res){WeixinJSBridge.log(res.err_msg);if(res.err_msg=="get_brand_wcpay_request:ok"){document.getElementById("payDom").style.display="none";document.getElementById("successDom").style.display="";setTimeout("window.location.href = \'' . $returnUrl . '\'",2000);}else{if(res.err_msg == "get_brand_wcpay_request:cancel"){var err_msg = "您取消了支付";}else if(res.err_msg == "get_brand_wcpay_request:fail"){var err_msg = "支付失败<br/>错误信息:"+res.err_desc;}else{var err_msg = res.err_msg +"<br/>"+res.err_desc;}document.getElementById("payDom").style.display = "none";document.getElementById("failDom").style.display = "";document.getElementById("failRt").innerHTML = err_msg;}});}</script>';
		}

		$message .= '</head><body style="padding-top:20px;"><style>.deploy_ctype_tip{z-index:1001;width:100%;text-align:center;position:fixed;top:50%;margin-top:-23px;left:0;}.deploy_ctype_tip p{display:inline-block;padding:13px 24px;border:solid #d6d482 1px;background:#f5f4c5;font-size:16px;color:#8f772f;line-height:18px;border-radius:3px;}</style><div id="payDom" class="cardexplain"><ul class="round"><li class="title mb"><span class="none">支付信息</span></li><li class="nob"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="kuang"><tr><th>金额</th><td>' . $price . '元</td></tr></table></li></ul>';

		if ($this->_issystem) {
			$message .= '<ul class="round" id="cross_pay"><li class="title mb" style="text-align:center"><span class="none">微信扫描支付</span></li><li class="nob" style="margin-bottom: 18px;"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="kuang"><tr><td style="text-align:center" ><img src="' . U('Weixin/qrcode', array('url' => $url)) . '" height="200" id="show_success"></td></tr><tr><td style="text-align:center">长按图片[识别二维码]付款</td></tr></table></li><li class="mb" style="text-align:center;margin-top: 20px;border-top: 1px solid #C6C6C6;" id="success"><span class="none"><a href="' . $returnUrl . '" style="color:#459ae9">我已经支付成功</a></span></li></ul>';
		}
		else {
			$message .= '<div class="footReturn" style="text-align:center" id="pay_div"><input type="button" style="margin:0 auto 20px auto;width:100%"  onclick="callpay()"  class="submit" value="点击进行微信支付" /></div>';
		}

		$message .= '</div><div id="failDom" style="display:none" class="cardexplain"><ul class="round"><li class="title mb"><span class="none">支付结果</span></li><li class="nob"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="kuang"><tr><th>支付失败</th><td><div id="failRt"></div></td></tr></table></li></ul><div class="footReturn" style="text-align:center"><input type="button" style="margin:0 auto 20px auto;width:100%"  onclick="callpay()"  class="submit" value="重新进行支付" /></div></div><div id="successDom" style="display:none" class="cardexplain"><ul class="round"><li class="title mb"><span class="none">支付成功</span></li><li class="nob"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="kuang"><tr><td>您已支付成功,页面正在跳转...</td></tr></table><div id="failRt"></div></li></ul></div></body></html>';
		echo $message;
	}
コード例 #19
0
ファイル: payaction.php プロジェクト: jasonhzy/bjcms
//总金额
$unifiedOrder->setParameter("notify_url", WEBSITE_ROOT . 'notify/weixin_notify.php');
//通知地址
$unifiedOrder->setParameter("trade_type", "JSAPI");
//交易类型
$unifiedOrder->setParameter("product_id", $order['id']);
//商品ID
//非必填参数,商户可根据实际情况选填
//$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");//用户标识
$jsApi = new JsApi_pub();
$prepay_id = $unifiedOrder->getPrepayId();
//=========步骤3:使用jsapi调起支付============
$jsApi->setPrepayId($prepay_id);
$jsApiParameters = $jsApi->getParameters();
?>

<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <title>微信安全支付</title>

	<script type="text/javascript">

	document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {

			WeixinJSBridge.invoke(
コード例 #20
0
ファイル: call.php プロジェクト: annehaha/digo
<?php

/**
 * JS_API支付demo
 * ====================================================
 * 在微信浏览器里面打开H5网页中执行JS调起支付。接口输入输出数据格式为JSON�?
 * 成功调起支付需要三个步骤:
 * 步骤1:网页授权获取用户openid
 * 步骤2:使用统一支付接口,获取prepay_id
 * 步骤3:使用jsapi调起支付
*/
include_once "WxPayPubHelper/WxPayPubHelper.php";
//使用jsapi接口
$jsApi = new JsApi_pub();
//=========步骤1:网页授权获取用户openid============
//通过code获得openid
if (!isset($_GET['code'])) {
    //触发微信返回code�?
    //$url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL);
    $url = $jsApi->createOauthUrlForCode('http://mydgsd.com/digo/call.php?money=' . $_GET['money']);
    Header("Location: {$url}");
} else {
    //获取code码,以获取openid
    $code = $_GET['code'];
    $jsApi->setCode($code);
    $openid = $jsApi->getOpenId();
    //	mylog("openid:".$openid);
}
//=========步骤2:使用统一支付接口,获取prepay_id============
//使用统一支付接口
$unifiedOrder = new UnifiedOrder_pub();
コード例 #21
0
ファイル: site.php プロジェクト: wisemyth/weizan
 public function doMobileAjaxPay()
 {
     global $_W, $_GPC;
     $price = $_GPC['price'];
     if ($price == 0) {
         $price = 0.01;
     }
     $uniacid = $_W['uniacid'];
     $set = pdo_fetch("SELECT * FROM " . tablename('fineness_sysset') . " WHERE weid=:weid limit 1", array(':weid' => $uniacid));
     if (empty($set)) {
         $res['code'] = 501;
         $res['msg'] = "抱歉,基本参数没设置";
         return json_encode($res);
     }
     load()->model('mc');
     $userInfo = mc_oauth_userinfo();
     $jsApi = new JsApi_pub($set);
     $jsApi->setOpenId($userInfo['openid']);
     $unifiedOrder = new UnifiedOrder_pub($set);
     $unifiedOrder->setParameter("openid", $userInfo['openid']);
     //商品描述
     $unifiedOrder->setParameter("body", "赞赏");
     //商品描述
     $timeStamp = time();
     $out_trade_no = $set['appid'] . "{$timeStamp}";
     $unifiedOrder->setParameter("out_trade_no", $out_trade_no);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", $price * 100);
     //总金额
     $notifyUrl = $_W['siteroot'] . "addons/" . AMOUSE_ARTICLE . "/notify.php";
     $unifiedOrder->setParameter("notify_url", $notifyUrl);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $prepay_id = $unifiedOrder->getPrepayId();
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $res['code'] = 200;
     $res['msg'] = $jsApiParameters;
     return json_encode($res);
 }
コード例 #22
0
ファイル: wx.jsapi.php プロジェクト: Jv-Juven/carService
<?php

/**
 * 微信用户的openid获取请参考官方demo sdk和文档
 * https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=11_1
 * 微信获取openid php代码, 运行环境是微信内置浏览器访问时
 */
include_once 'dependency/WxPayPubHelper/WxPayPubHelper.php';
include_once '../../sdk/beecloud.php';
$jsApi = new JsApi_pub();
//网页授权获取用户openid============
//通过code获得openid
if (!isset($_GET['code'])) {
    //触发微信返回code码
    $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL);
    Header("Location: {$url}");
} else {
    //获取code码,以获取openid
    $code = $_GET['code'];
    $jsApi->setCode($code);
    $openid = $jsApi->getOpenId();
}
$data = array();
$appSecret = "39a7a518-9ac8-4a9e-87bc-7885f33cf18c";
$data["app_id"] = "c5d1cba1-5e3f-4ba0-941d-9b0a371fe719";
$data["timestamp"] = time() * 1000;
$data["app_sign"] = md5($data["app_id"] . $data["timestamp"] . $appSecret);
$data["channel"] = "WX_JSAPI";
$data["total_fee"] = 1;
$data["bill_no"] = "bcdemo" . $data["timestamp"];
$data["title"] = "白开水";
コード例 #23
0
ファイル: site.php プロジェクト: aspnmy/weizan
 /**
  * author: 微赞
  */
 public function doMobileOrderPay()
 {
     global $_W, $_GPC;
     $oid = $_GPC['oid'];
     $order = DBUtil::findById(DBUtil::$TABLE_ORDER_ORDER, $oid);
     MonUtil::emtpyMsg($order, "订单删除或不存在");
     $item = DBUtil::findById(DBUtil::$TABLE_ORDER_ITEM, $order['iid']);
     $form = DBUtil::findById(DBUtil::$TABLE_ORDER_FORM, $order['fid']);
     if ($order['status'] == $this::$STATUS_UNPAY && $order['pay_type'] == 1) {
         //立即支付
         $jsApi = new JsApi_pub($this->mOrderSetting);
         $jsApi->setOpenId($order['openid']);
         $unifiedOrder = new UnifiedOrder_pub($this->mOrderSetting);
         $unifiedOrder->setParameter("openid", $order['openid']);
         //商品描述
         $unifiedOrder->setParameter("body", "预约订单" . $item['iname']);
         //商品描述
         $out_trade_no = date("YmdHis", TIMESTAMP);
         $unifiedOrder->setParameter("out_trade_no", $out_trade_no);
         //商户订单号
         //$unifiedOrder->setParameter("total_fee", 1);//总金额
         $unifiedOrder->setParameter("total_fee", $order['zf_price'] * 100);
         //总金额
         $notifyUrl = $_W['siteroot'] . "addons/" . MON_ORDER . "/notify.php";
         $unifiedOrder->setParameter("notify_url", $notifyUrl);
         //通知地址
         $unifiedOrder->setParameter("trade_type", "JSAPI");
         //交易类型
         $prepay_id = $unifiedOrder->getPrepayId();
         $jsApi->setPrepayId($prepay_id);
         $jsApiParameters = $jsApi->getParameters();
         DBUtil::updateById(DBUtil::$TABLE_ORDER_ORDER, array('outno' => $out_trade_no), $oid);
     }
     include $this->template("orderPay");
 }
コード例 #24
0
ファイル: function.php プロジェクト: noikiy/sryy
/**
 * 	作用:微信JSAPI方式支付参数请求
 */
function jsapi_pay($param)
{
    Vendor('WxPayPubHelper.WxPayPubHelper');
    $jsApi = new \JsApi_pub();
    $unifiedOrder = new \UnifiedOrder_pub();
    $unifiedOrder->setParameter("openid", $param['openid']);
    //用户openid
    $unifiedOrder->setParameter("body", $param['body']);
    //商品描述
    $unifiedOrder->setParameter("out_trade_no", $param['out_trade_no']);
    //商户订单号
    $unifiedOrder->setParameter("total_fee", $param['total_fee']);
    //总金额
    $unifiedOrder->setParameter("notify_url", C('SiteUrl') . "/Payment/paynotify");
    //通知地址
    $unifiedOrder->setParameter("trade_type", "JSAPI");
    //交易类型
    $prepay_id = $unifiedOrder->getPrepayId();
    //使用jsapi调起支付
    $jsApi->setPrepayId($prepay_id);
    $jsApiParameters = $jsApi->getParameters();
    return $jsApiParameters;
}
コード例 #25
0
ファイル: wxpay.php プロジェクト: TotoroLeon/wxpay_ecshop
 /**
  * 生成支付代码
  * 
  * @param array $order
  *        	订单信息
  * @param array $payment
  *        	支付方式信息
  */
 function get_code($order, $payment)
 {
     $conf = new WxPayConf_pub($payment);
     //微信浏览器的JSAPI支付\
     if (strpos($_SERVER['HTTP_USER_AGENT'], "MicroMessenger")) {
         $tools = new JsApi_pub($payment);
         $openid = $tools->GetOpenid();
         $unifiedOrder = new UnifiedOrder_pub();
         $returnrul = $conf->successurl;
         $unifiedOrder->setParameter("appid", $conf->wxpay_app_id);
         // appid
         $unifiedOrder->setParameter("openid", "{$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("spbill_create_ip", $_SERVER['REMOTE_ADDR']);
         $unifiedOrder->setParameter("notify_url", 'http://' . $_SERVER["HTTP_HOST"] . '/respond.php');
         // 通知地址
         $unifiedOrder->setParameter("trade_type", "JSAPI");
         // 交易类型
         // 非必填参数,商户可根据实际情况选填
         // $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();
         //var_dump($prepay_id);
         $jsApi = new JsApi_pub();
         $jsApi->setPrepayId($prepay_id);
         $jsApiParameters = $jsApi->getParameters();
         $pay_online = $jsApi->getbutton($jsApiParameters, $returnrul);
         return $pay_online;
     } else {
         $native = new NativeLink_pub($payment);
         //var_dump($order);die();
         $native->setParameter("body", $order['order_sn']);
         // 商品描述
         $timeStamp = time();
         // $out_trade_no = WxPayConf_pub::APPID."$timeStamp";
         $native->setParameter("appid", $conf->wxpay_app_id);
         // openid
         $native->setParameter("out_trade_no", $order['order_sn']);
         // 商户订单号
         $native->setParameter("total_fee", intval($order['order_amount'] * 100));
         // 总金额
         $native->setParameter("notify_url", $conf->notifyurl);
         // 通知地址
         $native->setParameter("trade_type", "NATIVE");
         // 交易类型
         $native->setParameter("product_id", $order['order_id']);
         $url = $native->getUrl();
         return $url;
         // 			// 非必填参数,商户可根据实际情况选填
         // 			// $unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号
         // 			// $unifiedOrder->setParameter("device_info","XXXX");//设备号
         // 			// $unifiedOrder->setParameter("attach","XXXX");//附加数据
         // 			 $unifiedOrder->setParameter("time_start",date ( "YmdHis" ));//交易起始时间
         // 			 $unifiedOrder->setParameter("time_expire",date ( "YmdHis", time () + 600 ));//交易结束时间
         // 			// $unifiedOrder->setParameter("goods_tag","XXXX");//商品标记
         // 			// $unifiedOrder->setParameter("openid","XXXX");//用户标识
         // 			// $unifiedOrder->setParameter("product_id","XXXX");//商品ID
     }
 }
コード例 #26
0
ファイル: WxPay.class.php プロジェクト: Molly2Molly/fiance
 /**
  * 微信红包发放
  * $dataArr 提交参数内容
  */
 function RedPackage($code, $dataArr = array())
 {
     $hongbao = new RedPackage();
     $jsApi = new JsApi_pub();
     if (!isset($code)) {
         //触发微信返回code码
         $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::RED_API_CALL_URL);
         Header("Location: {$url}");
     } else {
         //获取code码,以获取openid
         //$code = $_GET['code'];
         $jsApi->setCode($code);
         $openid = $jsApi->getOpenId();
     }
     $hongbao->setParameter("mch_billno", $dataArr['mch_billno']);
     //微信订单号
     $hongbao->setParameter("nick_name", $dataArr['nick_name']);
     //商户退款单号
     $hongbao->setParameter("send_name", $dataArr['send_name']);
     //总金额
     $hongbao->setParameter("re_openid", $openid);
     //退款金额
     $hongbao->setParameter("total_amount", $dataArr['total_amount']);
     //退款金额
     $hongbao->setParameter("min_value", $dataArr['min_value']);
     //退款金额
     $hongbao->setParameter("max_value", $dataArr['max_value']);
     //退款金额
     $hongbao->setParameter("total_num", $dataArr['total_num']);
     //退款金额
     $hongbao->setParameter("wishing", $dataArr['wishing']);
     //退款金额
     $hongbao->setParameter("client_ip", $dataArr['client_ip']);
     //退款金额
     $hongbao->setParameter("act_name", $dataArr['act_name']);
     //退款金额
     $hongbao->setParameter("remark", $dataArr['remark']);
     //退款金额
     //调用结果
     $hongbaoResult = $hongbao->getResult();
     echo "错误代码:" . $hongbaoResult['err_code'] . "<br>";
     echo "错误代码描述:" . $hongbaoResult['err_code_des'] . "<br>";
 }
コード例 #27
0
ファイル: js_api_call.php プロジェクト: wfqdreamcity/wellcn
 * ====================================================
 * 在微信浏览器里面打开H5网页中执行JS调起支付。接口输入输出数据格式为JSON。
 * 成功调起支付需要三个步骤:
 * 步骤1:网页授权获取用户openid
 * 步骤2:使用统一支付接口,获取prepay_id
 * 步骤3:使用jsapi调起支付
*/
include_once "./WxPayPubHelper/WxPayPubHelper.php";
session_start();
if (isset($_GET['order_sn']) && isset($_GET['goods_name']) && isset($_GET['order_amount'])) {
    $_SESSION['out_trade_no'] = $_GET['order_sn'];
    $_SESSION['goods_name'] = $_GET['goods_name'];
    $_SESSION['order_amount'] = $_GET['order_amount'];
}
//使用jsapi接口
$jsApi = new JsApi_pub();
//=========步骤1:网页授权获取用户openid============
//通过code获得openid
if (!isset($_GET['code'])) {
    //触发微信返回code码
    $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL);
    Header("Location: {$url}");
} else {
    //获取code码,以获取openid
    $code = $_GET['code'];
    $jsApi->setCode($code);
    $openid = $jsApi->getOpenId();
}
//=========步骤2:使用统一支付接口,获取prepay_id============
//使用统一支付接口
$unifiedOrder = new UnifiedOrder_pub();
コード例 #28
0
require dirname(__FILE__) . '/includes/modules/payment/weixin/WxPayPubHelper.php';
if ((DEBUG_MODE & 2) != 2) {
    $smarty->caching = true;
}
if ($_CFG['is_distrib'] == 0) {
    show_message('没有开启微信分销服务!', '返回首页', 'index.php');
}
$user_id = intval($_GET['user_id']);
if ($_SESSION['user_id'] != $user_id && $user_id > 0) {
    $weixinconfig = $GLOBALS['db']->getRow("SELECT * FROM " . $GLOBALS['ecs']->table('weixin_config') . " WHERE `id` = 1");
    define(APPID, $weixinconfig['appid']);
    // appid
    define(APPSECRET, $weixinconfig['appsecret']);
    // appSecret
    $selfUrl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
    $jsApi = new JsApi_pub();
    if (!isset($_GET['code'])) {
        // 触发微信返回code码
        $url = $jsApi->createOauthUrlForCode($selfUrl);
        Header("Location: {$url}");
        exit;
    } else {
        // 获取code码,以获取openid
        $code = $_GET['code'];
        $jsApi->setCode($code);
        $openid = $jsApi->getOpenId();
    }
    if ($openid) {
        //判断该微信是否已注册
        $sql = "SELECT count(*) FROM " . $GLOBALS['ecs']->table('weixin_user') . " WHERE fake_id = '{$openid}'";
        $count = $GLOBALS['db']->getOne($sql);
コード例 #29
0
 public function actionJspay()
 {
     // echo "string";
     //使用jsapi接口
     $jsApi = new \JsApi_pub();
     //如果是直接include过来的要在new 的类名前面加一个 反斜杠 \ 才可以 解析
     $form = Yii::$app->request->get();
     //获取地址栏中get过来的信息
     if (!empty($form['id'])) {
         $id = $form['id'];
     }
     //=========步骤1:网页授权获取用户openid============
     //通过code获得openid
     if (!isset($_GET['code'])) {
         //触发微信返回code码
         $redirect_uri = urlencode(\WxPayConf_pub::JS_API_CALL_URL);
         $url = $jsApi->createOauthUrlForCode($redirect_uri, $id);
         // echo $url;exit;
         return $this->redirect($url);
         //用yii自带的跳转
         // Header("Location: $url"); //这里不会跳转,用yii自带的跳转
     } else {
         //获取code码,以获取openid
         $code = $_GET['code'];
         $jsApi->setCode($code);
         $session = Yii::$app->session;
         $session->isActive ? '' : $session->open();
         if (!empty($_SESSION['pay']['openid'])) {
             $openid = $_SESSION['pay']['openid'];
         } else {
             $openid = $jsApi->getOpenId();
             $_SESSION['pay']['openid'] = $openid;
         }
         $form = Yii::$app->request->get();
         $id = intval($form['state']);
         // echo $id.'h';//测试回掉id成功
     }
     /* 通过id获取订单信息 */
     $orderBase = Order::find()->where(['id' => $id])->asArray()->one();
     $price = $orderBase['totalpay'] * 100;
     //价格
     $mobile = $orderBase['mobile'];
     $truename = $orderBase['truename'];
     $address = $orderBase['address'];
     $out_trade_no = $orderBase['orderno'];
     // echo $price.'<br />';
     // echo $address.'<br />';
     // echo $truename.'<br />';
     // echo $out_trade_no.'<br />';
     // exit;
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $unifiedOrder = new \UnifiedOrder_pub();
     //设置统一支付接口参数
     //设置必填参数
     //appid已填,商户无需重复填写
     //mch_id已填,商户无需重复填写
     //noncestr已填,商户无需重复填写
     //spbill_create_ip已填,商户无需重复填写
     //sign已填,商户无需重复填写
     $unifiedOrder->setParameter("openid", "{$openid}");
     //商品描述
     $unifiedOrder->setParameter("body", "365活动");
     //商品描述
     //自定义订单号,此处仅作举例
     $timeStamp = time();
     // $out_trade_no = \WxPayConf_pub::APPID."$timeStamp";
     // echo $out_trade_no;
     // $out_trade_no = $out_trade_no;
     $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
     //商户订单号 此处变量要用大括号阔起来
     $unifiedOrder->setParameter("total_fee", "{$price}");
     //总金额
     $unifiedOrder->setParameter("notify_url", \WxPayConf_pub::NOTIFY_URL);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     //非必填参数,商户可根据实际情况选填
     //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号
     //$unifiedOrder->setParameter("device_info","XXXX");//设备号
     //$unifiedOrder->setParameter("attach","XXXX");//附加数据
     $unifiedOrder->setParameter("time_start", date('YmdHis'));
     //交易起始时间
     $time_expire = date("YmdHis", strtotime("+7 day"));
     $unifiedOrder->setParameter("time_expire", "{$time_expire}");
     //交易结束时间
     // $unifiedOrder->setParameter("time_expire",date('YmdHis'));//交易结束时间
     $unifiedOrder->setParameter("goods_tag", "红叶");
     //商品标记
     //$unifiedOrder->setParameter("openid","XXXX");//用户标识
     $unifiedOrder->setParameter("product_id", "0008");
     //商品ID
     // ECHO $openid.'--P1';
     $prepay_id = $unifiedOrder->getPrepayId();
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $this->layout = false;
     //调用个人中心的布局
     return $this->render('pay', ['jsApiParameters' => $jsApiParameters, 'relprice' => $orderBase['totalpay'], 'mobile' => $mobile, 'truename' => $truename, 'address' => $address, 'out_trade_no' => $out_trade_no]);
     //显示页面,同时把$jsApiParameters 发送至页面
 }
コード例 #30
0
ファイル: wxpay.php プロジェクト: dlpc/ecshop
 /**
  * 生成支付代码
  * @param   array   $order      订单信息
  * @param   array   $payment    支付方式信息
  */
 function get_code($order, $payment)
 {
     $openid = 'oKIVft4Hk9gNczpAyszvsIYeGklU';
     //测试
     $unifiedOrder = new UnifiedOrder_pub();
     $conf = new WxPayConf_pub();
     $returnrul = $conf->successurl . $order["order_id"];
     //var_dump($returnrul);
     //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("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();
     $pay_online = $jsApi->getbutton($jsApiParameters, $returnrul);
     return $pay_online;
 }