public function toLogin() { if (Util::inWeixin()) { $this->toWxLogin(); } else { $this->toDefaultLogin(); } }
public function wxJsApiPay($orderId, $orderDesc, $totalAmount) { $openInfo = WxSDK::getOpenInfo('snsapi_base', WX_PAY_APP_ID, WX_PAY_APP_SECRET); if (empty($openInfo['openid'])) { $this->ajaxReturn(ERR_SYSTEM_ERROR, '向微信请求支付信息失败,稍重试'); return; } $openid = $openInfo['openid']; PayModel::onCreateOrderOk($orderId, array('pay_type' => PayModel::PAY_TYPE_WX)); $jsApiParameters = WxSDK::jsApiPay(WX_PAY_MCHID, WX_PAY_APP_ID, WX_PAY_KEY, $openid, $orderId, $orderDesc, ceil($totalAmount * 100), Util::getIp(), APP_URL_BASE . '/pay/PayNotify/wxUnified'); if ($jsApiParameters === false) { $this->ajaxReturn(ERR_SYSTEM_ERROR, '向微信申请支付失败,稍重试'); return; } $this->ajaxReturn(0, '', '', array('jsapiparams' => $jsApiParameters)); }
public function toLogin() { if (Util::inWeixin()) { $openid = $this->toWxLogin(); if ($openid !== false) { if ($this->doLoginInWx($openid) === true) { UserModel::onLoginOk(0, $openid); } else { // } } else { // } } else { $this->toDefaultLogin(); } }
public static function getSomeComment($goodsId, $nextId, $size) { if (empty($goodsId) || $size <= 0) { return array(); } $nextId = (int) $nextId; if ($nextId > 0) { $ret = DB::getDB()->fetchSome('g_goods_comment', '*', array('goods_id', 'state', 'id<'), array($goodsId, self::COMMENT_ST_VALID, $nextId), array('and', 'and'), array('id'), array('desc'), array($size)); } else { $ret = DB::getDB()->fetchSome('g_goods_comment', '*', array('goods_id', 'state'), array($goodsId, self::COMMENT_ST_VALID), array('and'), array('id'), array('desc'), array($size)); } if (empty($ret)) { return array(); } foreach ($ret as &$item) { $item['nickname'] = Util::emojiDecode($item['nickname']); $item['content'] = Util::emojiDecode($item['content']); $item['kf_reply'] = Util::emojiDecode($item['kf_reply']); } return empty($ret) ? array() : $ret; }
public function wxJsApiPay() { $openInfo = WxSDK::getOpenInfo('snsapi_base', WX_PAY_APP_ID, WX_PAY_APP_SECRET); if (empty($openInfo['openid'])) { echo '向微信请求支付失败,稍重试'; return; } $openid = $openInfo['openid']; $orderId = date('Ymd') . mt_rand(1000000000, 1999999999); PayModel::onCreateOrderOk($orderId, array('pay_type' => PayModel::PAY_TYPE_WX)); $jsApiParameters = WxSDK::jsApiPay(WX_PAY_MCHID, WX_PAY_APP_ID, WX_PAY_KEY, $openid, $orderId, '测试1分钱商品', 1, Util::getIp(), APP_URL_BASE . '/pay/PayNotify/wxUnified'); if ($jsApiParameters === false) { echo '获取js参数失败'; exit; } echo <<<HTML <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <title>微信支付样例-支付</title> <script type="text/javascript"> //调用微信JS api 支付 function jsApiCall() { WeixinJSBridge.invoke( 'getBrandWCPayRequest', {$jsApiParameters}, function(res){ WeixinJSBridge.log(res.err_msg); if (res.err_msg == "get_brand_wcpay_request:ok") { setTimeout(function() { location.href = "http://host/pay/OrderPay/wxPayReturn"; }, 500); } else { if (res.err_msg != "get_brand_wcpay_request:cancel") { alert(res.err_code+res.err_desc+res.err_msg); } } } ); } function callpay() { if (typeof WeixinJSBridge == "undefined"){ if( document.addEventListener ){ document.addEventListener('WeixinJSBridgeReady', jsApiCall, false); }else if (document.attachEvent){ document.attachEvent('WeixinJSBridgeReady', jsApiCall); document.attachEvent('onWeixinJSBridgeReady', jsApiCall); } }else{ jsApiCall(); } } </script> </head> <body> <br/> <font color="#9ACD32"><b>该笔订单支付金额为<span style="color:#f00;font-size:50px">1分</span>钱</b></font><br/><br/> <div align="center"> <button style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" >立即支付</button> </div> </body> </html> HTML; }
public static function getRandomNickname($prefix) { return $prefix . Util::getRandomStr(5); // TODO }
public static function findUserByOpenId($openid, $fromDb = 'w') { if (empty($openid)) { return array(); } $ck = Cache::CK_WX_USER_INFO . $openid; $ret = Cache::get($ck); if ($ret !== false) { $ret = json_decode($ret, true); } else { $ret = DB::getDB($fromDb)->fetchOne('u_wx_user', '*', array('openid'), array($openid)); if ($ret !== false) { Cache::set($ck, json_encode($ret)); } } if (empty($ret)) { return array(); } $ret['nickname'] = Util::emojiDecode($ret['nickname']); return $ret; }