| // +------------------------------------------------+ namespace app\mobile\controller; use app\common\service\Score as ScoreService; use app\common\service\Vip as VipService; use cjango\Wechat; class Pay extends _Init { public function vip($openid = '') { parent::initWechat(); if (!$openid) { $url = Wechat\Oauth::url(url('Pay/getOpenId', 'callback=' . __SELF__)); $this->redirect($url); } $fee = 298; $res = VipService::createPayOrder(UID, $fee, $openid); if ($res['code'] != 1) { return $res['msg']; exit(); } $this->orderid = $res['data']; parent::initWechat(); $this->payParams = Wechat\Pay::unified($this->orderid, '超级助手VIP(有效期一年)', $fee, 'JSAPI', url('openapi/pay/vip'), $openid); if ($this->payParams == false) { echo Wechat::error(); exit(); } return $this->fetch(); } public function getOpenId($callback) { parent::initWechat(); $token = Wechat\Oauth::token(); if ($token) { $openid = $token['openid']; $this->redirect($callback . '?openid=' . $openid); } else { echo Wechat::error(); } } /** * 兑换会员 * @param [type] $orderid [description] * @return [type] [description] */ public function exchange($orderid) { $res = ScoreService::buyVip(UID, $orderid); if ($res == 1) { $res = true; } return $this->back($res); } }