1、会员卡的领取也需要js-sdk接口(可以参考获取微信公众号获取用户的地理位置信息)(借鉴网址:http://gaoboy.com/article/25.html)

2、 比获取用户地理位置信息多了一个是需要单独获取签名包,签名方式也和获取用户地理位置的不同(这里再说一下获取签名包的方式)

      获取js-sdk签名包:

           1、当前的url、时间戳、随机字符串、jsapiticket进行组合                

 //调用js-sdk的签名包
 public function getSignPackage() {
 $jsapiTicket = $this->getJsApiTicket();
 // 注意 URL 一定要动态获取,不能 hardcode.(获取当前网页的url)
 $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) "https://" : "http://";
 $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
 //时间戳
 $timestamp = time();
 //随机字符串获取
 $nonceStr = $this->createNonceStr();
 // 这里参数的顺序要按照 key 值 ASCII 码升序排序
 $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
 //生成字符串是用来签名用的
 $signature = sha1($string);
 $signPackage = array(
  "appId"  => $this->appid,
  "nonceStr" => $nonceStr,
  "timestamp" => $timestamp,
  "url"  => $url,
  "signature" => $signature,
  "rawString" => $string
 );
 return $signPackage; 
 }

     获取会员卡签名包:      

//使用会员卡领取的签名包
 public function getHuiYuanSignPackage() {
 $apiTicket = $this->getApiTicket();
 // 注意 URL 一定要动态获取,不能 hardcode.(获取当前网页的url)
 $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) "https://" : "http://";
 $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
 //时间戳
 $timestamp = time();
 //随机字符串获取
 // $nonceStr = $this->createNonceStr();
 // 这里参数的顺序要按照 key 值 ASCII 码升序排序
 $string = $timestamp.$apiTicket."pVYA_t3RCVF_yhNcO6QCeAmb-1UI";
 //生成字符串是用来签名用的
 $signature = sha1($string);
 $signPackage = array(
  "timestamp" => $timestamp,
  "signature" => $signature,
 );
 return $signPackage; 
 }

详细代码说明:

     HTML页面:         

  //引入微信js文件
   <script src="/UploadFiles/2021-04-02/jweixin-1.0.0.js">

控制器中的代码:

   类库:https://www.jb51.net/article/115732.htm

 public function index(){
 $user_id = session('user_id');
  if($user_id){
  $jssdk = new \Home\Model\WechatModel();
  $signPackage = $jssdk->GetSignPackage();//获取js-sdk签名包
  $huiyuanPackage = $jssdk->getHuiYuanSignPackage();获取会员卡签名包
  //获取用户信息 
  $user = M('user')->where(array('user_id' => $user_id))->find();
  //产品收藏数量统计
  $goods_count = M('goods_shoucang')->where(array('user_id' => $user_id))->count();
  //门店收藏数量统计
  $shop_count = M('shop_shoucang')->where(array('user_id' => $user_id))->count();
  }else{
  //判断该用户是否存在
  $model = new \Home\Model\WechatModel();
  $openid_accesstoken = $model->openId();
  $rst = M('user')->where(array('user_openid' => $openid_accesstoken['openid']))->find();
  if($rst){
   session('openid',$openid_accesstoken['openid']);
   session('user_id', $rst['user_id']);
   $jssdk = new \Home\Model\WechatModel();
   $signPackage = $jssdk->GetSignPackage();
   $huiyuanPackage = $jssdk->getHuiYuanSignPackage();
   //获取用户信息 
   $user = M('user')->where(array('user_id' => $rst['user_id']))->find();
   //产品收藏数量统计
   $goods_count = M('goods_shoucang')->where(array('user_id' => $rst['user_id']))->count();
   //门店收藏数量统计
   $shop_count = M('shop_shoucang')->where(array('user_id' => $rst['user_id']))->count();
  }else{
   $userInfo = $model->getOpenId($openid_accesstoken['openid'],$openid_accesstoken['access_token']);
     $data = array(
      'user_img' => $userInfo['headimgurl'],
      'user_openid' => $userInfo['openid'],
      'user_name' => filter($userInfo['nickname']),
      'user_register_time' => time(),
      'city' => $userInfo['province'].'-'.$userInfo['city'],
     );
   $id = M('user')->add($data);
   session('openid', $userInfo['openid']);
   session('user_id',$id);
   $jssdk = new \Home\Model\WechatModel();
   $signPackage = $jssdk->GetSignPackage();
   $huiyuanPackage = $jssdk->getHuiYuanSignPackage();
   //获取用户信息 
   $user = M('user')->where(array('user_id' => $id))->find();
   //产品收藏数量统计
   $goods_count = M('goods_shoucang')->where(array('user_id' => $id))->count();
   //门店收藏数量统计
   $shop_count = M('shop_shoucang')->where(array('user_id' => $id))->count();
   }
  }
  $this->assign('signPackage', $signPackage);
  $this->assign('huiyuanPackage', $huiyuanPackage);
  $this->assign('user', $user);
  $this->assign('shop_count', $shop_count);
  $this->assign('goods_count', $goods_count);
  $this->display();
 }

以上所述是小编给大家介绍的微信公众号实现会员卡领取功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。