first commit
This commit is contained in:
67
application/mobile/controller/Pay.php
Normal file
67
application/mobile/controller/Pay.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user