diff --git a/app/portal/controller/SalesmangoodsController.php b/app/portal/controller/SalesmangoodsController.php index 756d233..30b0038 100644 --- a/app/portal/controller/SalesmangoodsController.php +++ b/app/portal/controller/SalesmangoodsController.php @@ -202,6 +202,78 @@ class SalesmangoodsController extends WeChatBaseController{ } + // 获取签名 + public function getSignPackage() { + // 获取token + $token = $this->getAccessToken(); + // 获取ticket + $ticketList = $this->getJsApiTicket($token['accessToken']); + $ticket = $ticketList['ticket']; + // 该URL为使用JSSDK接口的URL + $url = $_GET['url']; + if (!$url) { + $url = 'http://xxx.xxx.com/index/index.html'; + } + // 时间戳 + $timestamp = time(); + // 随机字符串 + $nonceStr = $this->createNoncestr(); + // 这里参数的顺序要按照 key 值 ASCII 码升序排序 j -> n -> t -> u + $string = "jsapi_ticket=$ticket&noncestr=$nonceStr×tamp=$timestamp&url=$url"; + $signature = sha1($string); + $signPackage = array ( + "appId" => C('WxPayConf_pub.APPID'), + "nonceStr" => $nonceStr, + "timestamp" => $timestamp, + "url" => $url, + "signature" => $signature, + "rawString" => $string, + "ticket" => $ticket, + "token" => $token['accessToken'] + ); + // 提供数据给前端 + $this->ajaxReturn(array('status' => true, 'data' => $signPackage)); + } + + public function getAccessToken() { + // access_token 应该全局存储与更新 + // 获取数据库中的access_token + $token = M('accesstoken')->limit(1)->find(); + // 如果数据库存在token + if ($token) { + // 格式化数据库的timestamp + $time = strtotime($token['time']); + } + // accessToken过期或不存在时 + if($time + $token['expiresIn'] < time() || $token['accessToken'] == NULL){ + $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".C('WxPayConf_pub.APPID')."&secret=".C('WxPayConf_pub.APPSECRET'); + // 微信返回的信息 + $returnData = json_decode($this->httpGet($url)); + // 组装数据 + $resData['accessToken'] = $returnData->access_token; + $resData['expiresIn'] = $returnData->expires_in; + $resData['time'] = date("Y-m-d H:i",time()); + // 把数据存进数据库 + M('accesstoken')->where(array('id' => $token['id']))->save($resData); + $res = $resData; + }else{ + $res = $token; + } + return $res; + } + + + + + + + + + + + + + diff --git a/public/themes/simpleboot3/portal/salesmangoods/salesman_goods_add.html b/public/themes/simpleboot3/portal/salesmangoods/salesman_goods_add.html index f1b6589..bc6e109 100644 --- a/public/themes/simpleboot3/portal/salesmangoods/salesman_goods_add.html +++ b/public/themes/simpleboot3/portal/salesmangoods/salesman_goods_add.html @@ -304,6 +304,11 @@ function openCamera(){ + + $.post("{:url('/')}",{},function (data) { + + }); + wx.chooseImage({ count: 1, // 默认9 sizeType: ['original'], // 指定是原图还是压缩图,默认都有 diff --git a/simplewind/cmf/controller/WeChatBaseController.php b/simplewind/cmf/controller/WeChatBaseController.php index aa6f301..53944f0 100644 --- a/simplewind/cmf/controller/WeChatBaseController.php +++ b/simplewind/cmf/controller/WeChatBaseController.php @@ -204,8 +204,8 @@ class WeChatBaseController extends BaseController */ public function checkWeChatUserLogin() { - $user = Db::name('user')->where('id',2)->find(); - cmf_update_current_user($user); + /*$user = Db::name('user')->where('id',5)->find(); + cmf_update_current_user($user);*/ $userId = cmf_get_current_user_id(); if (empty($userId)) { $config = [