Commit c002f2ce authored by houdong's avatar houdong

分享测试

parent 78ecd6b5
......@@ -907,7 +907,8 @@ var AppBridge = {
});
wx.error(function (res) {
//alert(res);
alert(res);
alert(JSON.stringify(res));
});
},
CreateOrder: function (groupId, type) {
......
......@@ -1423,6 +1423,7 @@ function trace_log($data,$ext='',$path='',$para=array()) {
$mtime = time();
$path = empty($path) ? APP_PATH.'Runtime/Logs/' : $path;
$logfile=$path.($ext?$ext:'') .'log_'.date('Ymd', $mtime) .'.log';
// var_dump($logfile);exit;
if(empty($para)){
@file_put_contents($logfile, date('Y-m-d H:i:s', $mtime)."\t" . $data . "\n", FILE_APPEND);
}else{
......
......@@ -197,7 +197,7 @@ return array(
),
'WXCONFIG'=>[
'AppID'=>'wx30d8a92906ae291b',
'AppSecret'=>'19e95210c22d9a42be2f41d21c083f58',
'AppSecret'=>'2f80d427fd7929b20d8fb9bfa854ae04',
// 'mch_id' => 1534106761,
// 'key' => 'LI1qR3jkWYB69W3weVBKmwine5dvF2bp6sdo6x3Z70N',
],
......
......@@ -631,7 +631,7 @@ class PkTopAction extends IdentityAction{
D('User')->addMoney($userId,$userName,$mobile);
D('User')->addInvite($userId,$userName);
//完成勋章
D('User')->finishXunzhang($userId,$userName,$mobile,'cansai');
// D('User')->finishXunzhang($userId,$userName,$mobile,'cansai');
return ['status'=>1,'info'=>'参赛成功','debug'=>$userId];
......@@ -882,6 +882,11 @@ class PkTopAction extends IdentityAction{
;
$this->assign('appParam',json_encode($appParam));
//定义在微信分享的显示
$signPackage=D('Share')->getSignPackage();
$this->assign('signPackage',json_encode($signPackage));
return $appShareInfo;
}
......
......@@ -8,10 +8,14 @@ class ShareModel extends Model{
private $appSecret='0b4c9fc96f1a4b32fc2a3793b60244e4';
public function _initialize($config = ''){
$this->appId = C('WXCONFIG.AppID');
$this->appSecret =C('WXCONFIG.AppSecret');
}
public function getSignPackage() {
trace_log('getSignPackage','wxShare_');
$jsapiTicket = $this->getJsApiTicket();
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
......@@ -50,7 +54,7 @@ class ShareModel extends Model{
public function getJsApiTicket() {
// jsapi_ticket 应该全局存储与更新,以下代码以写入到文件中做示例
$data = json_decode($this->get_php_file("jsapi_ticket4.php"));
$data = json_decode($this->get_php_file("vip_jsapi_ticket4.php"));
// var_dump($data);exit;
if (!$data||$data->expire_time < time()) {
$accessToken = $this->getAccessToken();
......@@ -58,12 +62,15 @@ class ShareModel extends Model{
// $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken";
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken";
// var_dump($url);exit;
$res = json_decode($this->httpGet($url));
// $res = json_decode($this->httpGet($url));
$httpRes=$this->httpGet($url);
$res = json_decode($httpRes);
trace_log("getJsApiTicket,url:".$url.',响应'.$httpRes,'wxShare_');
$ticket = $res->ticket;
if ($ticket) {
$data->expire_time = time() + 7000;
$data->jsapi_ticket = $ticket;
$this->set_php_file("jsapi_ticket4.php", json_encode($data));
$this->set_php_file("vip_jsapi_ticket4.php", json_encode($data));
}
} else {
$ticket = $data->jsapi_ticket;
......@@ -73,19 +80,23 @@ class ShareModel extends Model{
private function getAccessToken() {
// access_token 应该全局存储与更新,以下代码以写入到文件中做示例
$data = json_decode($this->get_php_file("access_token4.php"));
$data = json_decode($this->get_php_file("vip_access_token4.php"));
if (!$data||$data->expire_time < time()) {
// 如果是企业号用以下URL获取access_token
// $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
// var_dump($url);
$res = json_decode($this->httpGet($url));
// $res = json_decode($this->httpGet($url));
$httpRes=$this->httpGet($url);
$res = json_decode($httpRes);
// var_dump($res);exit;
trace_log("getAccessToken,url:".$url.',响应'.$httpRes,'wxShare_');
$access_token = $res->access_token;
if ($access_token) {
$data->expire_time = time() + 7000;
$data->access_token = $access_token;
$this->set_php_file("access_token4.php", json_encode($data));
$this->set_php_file("vip_access_token4.php", json_encode($data));
}
} else {
$access_token = $data->access_token;
......
......@@ -171,7 +171,7 @@ class UserModel extends Model{
return [$entrustList,$total?$total:0];
}
//完成勋章
//完成勋章,只有参赛勋章
public function finishXunzhang($userId,$userName,$mobile,$xzType) {
$level=M('XunzhangLevel')->where(['user_id'=>$userId])->count();
if(!$level){
......@@ -182,6 +182,8 @@ class UserModel extends Model{
if(!$old){
$addData=['user_id'=>$userId,'user_name'=>$userName,'xz_id'=>$xzid,'mobile'=>$mobile];
$addData['add_time']=$addData['finish1_time']=$addData['finish2_time']=time();
//直接打开百宝箱,防止重复领取1.88元
$addData['openbox_time']=time();
M('XunzhangUser')->add($addData);
}
}
......
......@@ -200,6 +200,8 @@
});
});
// //微信内分享
AppBridge.wx_share({$signPackage},{$appParam});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment