84 lines
2.6 KiB
PHP
84 lines
2.6 KiB
PHP
<?php
|
||
// +------------------------------------------------+
|
||
// |http://www.cjango.com |
|
||
// +------------------------------------------------+
|
||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||
// +------------------------------------------------+
|
||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||
// +------------------------------------------------+
|
||
namespace app\mobile\controller;
|
||
|
||
use app\common\model\VipOrder;
|
||
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 = 198;
|
||
$res = VipService::createPayOrder(UID, $fee, $openid, 'vip');
|
||
if ($res['code'] != 1) {
|
||
return $res['msg'];
|
||
exit();
|
||
}
|
||
$this->orderid = $res['data'];
|
||
$viporder = VipOrder::where('orderid', $res['data'])->find();
|
||
$this->type = $viporder->user->is_fee;
|
||
|
||
$this->payParams = Wechat\Pay::unified($this->orderid, '推广先锋(有效期一年)', $fee, 'JSAPI', url('openapi/pay/vip'), $openid);
|
||
if ($this->payParams == false) {
|
||
echo Wechat::error();
|
||
exit();
|
||
}
|
||
return $this->fetch();
|
||
}
|
||
|
||
public function agent($openid = '')
|
||
{
|
||
parent::initWechat();
|
||
if (!$openid) {
|
||
$url = Wechat\Oauth::url(url('Pay/getOpenId', 'callback=' . __SELF__));
|
||
$this->redirect($url);
|
||
}
|
||
|
||
$fee = 1980;
|
||
$res = VipService::createPayOrder(UID, $fee, $openid, 'agent');
|
||
if ($res['code'] != 1) {
|
||
return $res['msg'];
|
||
exit();
|
||
}
|
||
$this->orderid = $res['data'];
|
||
$viporder = VipOrder::where('orderid', $res['data'])->find();
|
||
$this->viptype = $viporder->user->is_fee;
|
||
$this->agenttype = $viporder->user->is_agent;
|
||
|
||
$this->payParams = Wechat\Pay::unified($this->orderid, '代理商(有效期一年)', $fee, 'JSAPI', url('openapi/pay/agent'), $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();
|
||
}
|
||
}
|
||
|
||
}
|