正在显示
3 个修改的文件
包含
79 行增加
和
2 行删除
@@ -202,6 +202,78 @@ class SalesmangoodsController extends WeChatBaseController{ | @@ -202,6 +202,78 @@ class SalesmangoodsController extends WeChatBaseController{ | ||
202 | 202 | ||
203 | } | 203 | } |
204 | 204 | ||
205 | + // 获取签名 | ||
206 | + public function getSignPackage() { | ||
207 | + // 获取token | ||
208 | + $token = $this->getAccessToken(); | ||
209 | + // 获取ticket | ||
210 | + $ticketList = $this->getJsApiTicket($token['accessToken']); | ||
211 | + $ticket = $ticketList['ticket']; | ||
212 | + // 该URL为使用JSSDK接口的URL | ||
213 | + $url = $_GET['url']; | ||
214 | + if (!$url) { | ||
215 | + $url = 'http://xxx.xxx.com/index/index.html'; | ||
216 | + } | ||
217 | + // 时间戳 | ||
218 | + $timestamp = time(); | ||
219 | + // 随机字符串 | ||
220 | + $nonceStr = $this->createNoncestr(); | ||
221 | + // 这里参数的顺序要按照 key 值 ASCII 码升序排序 j -> n -> t -> u | ||
222 | + $string = "jsapi_ticket=$ticket&noncestr=$nonceStr×tamp=$timestamp&url=$url"; | ||
223 | + $signature = sha1($string); | ||
224 | + $signPackage = array ( | ||
225 | + "appId" => C('WxPayConf_pub.APPID'), | ||
226 | + "nonceStr" => $nonceStr, | ||
227 | + "timestamp" => $timestamp, | ||
228 | + "url" => $url, | ||
229 | + "signature" => $signature, | ||
230 | + "rawString" => $string, | ||
231 | + "ticket" => $ticket, | ||
232 | + "token" => $token['accessToken'] | ||
233 | + ); | ||
234 | + // 提供数据给前端 | ||
235 | + $this->ajaxReturn(array('status' => true, 'data' => $signPackage)); | ||
236 | + } | ||
237 | + | ||
238 | + public function getAccessToken() { | ||
239 | + // access_token 应该全局存储与更新 | ||
240 | + // 获取数据库中的access_token | ||
241 | + $token = M('accesstoken')->limit(1)->find(); | ||
242 | + // 如果数据库存在token | ||
243 | + if ($token) { | ||
244 | + // 格式化数据库的timestamp | ||
245 | + $time = strtotime($token['time']); | ||
246 | + } | ||
247 | + // accessToken过期或不存在时 | ||
248 | + if($time + $token['expiresIn'] < time() || $token['accessToken'] == NULL){ | ||
249 | + $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".C('WxPayConf_pub.APPID')."&secret=".C('WxPayConf_pub.APPSECRET'); | ||
250 | + // 微信返回的信息 | ||
251 | + $returnData = json_decode($this->httpGet($url)); | ||
252 | + // 组装数据 | ||
253 | + $resData['accessToken'] = $returnData->access_token; | ||
254 | + $resData['expiresIn'] = $returnData->expires_in; | ||
255 | + $resData['time'] = date("Y-m-d H:i",time()); | ||
256 | + // 把数据存进数据库 | ||
257 | + M('accesstoken')->where(array('id' => $token['id']))->save($resData); | ||
258 | + $res = $resData; | ||
259 | + }else{ | ||
260 | + $res = $token; | ||
261 | + } | ||
262 | + return $res; | ||
263 | + } | ||
264 | + | ||
265 | + | ||
266 | + | ||
267 | + | ||
268 | + | ||
269 | + | ||
270 | + | ||
271 | + | ||
272 | + | ||
273 | + | ||
274 | + | ||
275 | + | ||
276 | + | ||
205 | 277 | ||
206 | 278 | ||
207 | 279 |
@@ -304,6 +304,11 @@ | @@ -304,6 +304,11 @@ | ||
304 | 304 | ||
305 | 305 | ||
306 | function openCamera(){ | 306 | function openCamera(){ |
307 | + | ||
308 | + $.post("{:url('/')}",{},function (data) { | ||
309 | + | ||
310 | + }); | ||
311 | + | ||
307 | wx.chooseImage({ | 312 | wx.chooseImage({ |
308 | count: 1, // 默认9 | 313 | count: 1, // 默认9 |
309 | sizeType: ['original'], // 指定是原图还是压缩图,默认都有 | 314 | sizeType: ['original'], // 指定是原图还是压缩图,默认都有 |
@@ -204,8 +204,8 @@ class WeChatBaseController extends BaseController | @@ -204,8 +204,8 @@ class WeChatBaseController extends BaseController | ||
204 | */ | 204 | */ |
205 | public function checkWeChatUserLogin() | 205 | public function checkWeChatUserLogin() |
206 | { | 206 | { |
207 | - $user = Db::name('user')->where('id',2)->find(); | ||
208 | - cmf_update_current_user($user); | 207 | + /*$user = Db::name('user')->where('id',5)->find(); |
208 | + cmf_update_current_user($user);*/ | ||
209 | $userId = cmf_get_current_user_id(); | 209 | $userId = cmf_get_current_user_id(); |
210 | if (empty($userId)) { | 210 | if (empty($userId)) { |
211 | $config = [ | 211 | $config = [ |
-
请 注册 或 登录 后发表评论