Apiweapp.php
5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/**
* tpshop
* ============================================================================
* 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* Author: JY
* Date: 2015-09-23
*/
namespace app\home\controller;
use app\home\logic\UsersLogic;
use think\Db;
use think\Exception;
use think\Session;
use think\Controller;
use think\Verify;
use think\Cookie;
use think\Page;
class Apiweapp extends Controller
{
public function _initialize()
{
Session::start();
}
/*获取第三方平台TIKET*/
public function getcomponent_verify_ticket()
{
// try {
$component_verify_ticket =cache_new("wechat","component","component_verify_ticket");
$component_verify_ticket_time =cache_new("wechat","component","component_verify_ticket_time");
if (empty($component_verify_ticket))
{
$getcomponent_verify_ticket = file_get_contents(dirname(__FILE__)."/../../index/controller/static/component_verify_ticket.txt");//正式
$getcomponent_verify_tickettime = file_get_contents(dirname(__FILE__)."/../../index/controller/static/component_verify_ticket_time.txt");//正式
cache_new("wechat","component","component_verify_ticket",$getcomponent_verify_ticket);
cache_new("wechat","component","component_verify_ticket_time",$getcomponent_verify_tickettime+600);
$jsonres["STATE"] = -1;
$jsonres["MSG"] = "获取空值";
return json($jsonres);
}
$jsonres["STATE"] = 0;
$jsonres["MSG"] = "ok";
$jsonres["component_verify_ticket"]=$component_verify_ticket;
$jsonres["component_verify_ticket_time"]=date("Y-m-d H:i:s",$component_verify_ticket_time);
return json($jsonres);
// }
// catch (Exception $ex) {
// $jsonres["STATE"] = -1;
// $jsonres["MSG"] = "异常出错";
// return json($jsonres);
// }
}
/*更新第三方平台token*/
public function updatecomponent_access_token()
{
try {
$getcomponent_access_token=getcomponent_access_token();
if (empty($getcomponent_access_token))
{
$jsonres["STATE"] = -1;
$jsonres["MSG"] = "返回token空";
return json_encode($jsonres);
}
$jsonres["STATE"] = 0;
$jsonres["MSG"] = "ok";
$jsonres["ComponentAccessToken"]=$getcomponent_access_token;
return json_encode($jsonres);
}
catch (Exception $ex) {
$jsonres["STATE"] = -1;
$jsonres["MSG"] = "异常出错";
return json_encode($jsonres);
}
}
/*根据商户Id更新第三方平台token*/
public function weapp_authorizer_access_token()
{
$stoid=I("stoid/d",0);
try {
$weapp_get_access_token=weapp_get_access_token(null,$stoid,1);
if (empty($weapp_get_access_token))
{
$jsonres["STATE"] = -1;
$jsonres["MSG"] = "返回token空";
return json_encode($jsonres);
}
$res=json_decode($weapp_get_access_token,true);
if ($res['errcode']!=0) {
$jsonres["STATE"] = -1;
$jsonres["MSG"] = "失败";
return json_encode($jsonres);
}
$jsonres["STATE"] = 0;
$jsonres["MSG"] = "ok";
$jsonres["AuthorizerAccessToken"] = $res['authorizer_access_token'];
return json_encode($jsonres);
}
catch (Exception $ex) {
$jsonres["STATE"] = -1;
$jsonres["MSG"] = "异常出错";
return json_encode($jsonres);
}
}
/*根据商户appid更新第三方平台token*/
public function weapp_appid_authorizer_access_token()
{
$appid=I("appid");
if (empty($appid))
{
$jsonres["STATE"] = -1;
$jsonres["MSG"] = "商户APPID不能为空";
return json_encode($jsonres);
}
try {
$weapp_get_access_token=weapp_appid_get_access_token(null,$appid,1);
if (empty($weapp_get_access_token))
{
$jsonres["STATE"] = -1;
$jsonres["MSG"] = "返回token空";
return json_encode($jsonres);
}
$res=json_decode($weapp_get_access_token,true);
if ($res['errcode']!=0) {
$jsonres["STATE"] = -1;
$jsonres["MSG"] = "失败";
return json_encode($jsonres);
}
$jsonres["STATE"] = 0;
$jsonres["MSG"] = "ok";
$jsonres["AuthorizerAccessToken"] = $res['authorizer_access_token'];
return json_encode($jsonres);
}
catch (Exception $ex) {
$jsonres["STATE"] = -1;
$jsonres["MSG"] = "异常出错";
return json_encode($jsonres);
}
}
}