1
0
Files
2020-08-06 14:58:51 +08:00

68 lines
1.9 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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);
}
}