国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home WeChat Applet WeChat Development Share the WeChat public account to realize the function of receiving membership cards

Share the WeChat public account to realize the function of receiving membership cards

Jun 16, 2017 am 10:00 AM

This article mainly introduces the relevant information on the WeChat public account to realize the membership card collection function. Friends who need it can refer to

1. The collection of membership cards also requires the js-sdk interface (you can refer to Obtaining WeChat The public account obtains the user’s geographical location information) (reference URL: http://gaoboy.com/article/25.html)

2. One more thing than obtaining the user’s geographical location information is that you need to obtain the signature package separately. , the signature method is also different from obtaining the user's geographical location (here we will talk about the method of obtaining the signature package)

Obtain the js-sdk signature package:

1. The current URL, timestamp, random string, JSAPITICKET for combination

#
 //調(diào)用js-sdk的簽名包
 public function getSignPackage() {
 $jsapiTicket = $this->getJsApiTicket();
 // 注意 URL 一定要動態(tài)獲取,不能 hardcode.(獲取當(dāng)前網(wǎng)頁的url)
 $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
 $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
 //時間戳
 $timestamp = time();
 //隨機(jī)字符串獲取
 $nonceStr = $this->createNonceStr();
 // 這里參數(shù)的順序要按照 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; 
 }

## 獲##
//使用會員卡領(lǐng)取的簽名包
 public function getHuiYuanSignPackage() {
 $apiTicket = $this->getApiTicket();
 // 注意 URL 一定要動態(tài)獲取,不能 hardcode.(獲取當(dāng)前網(wǎng)頁的url)
 $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
 $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
 //時間戳
 $timestamp = time();
 //隨機(jī)字符串獲取
 // $nonceStr = $this->createNonceStr();
 // 這里參數(shù)的順序要按照 key 值 ASCII 碼升序排序
 $string = $timestamp.$apiTicket."pVYA_t3RCVF_yhNcO6QCeAmb-1UI";
 //生成字符串是用來簽名用的
 $signature = sha1($string);
 $signPackage = array(
  "timestamp" => $timestamp,
  "signature" => $signature,
 );
 return $signPackage; 
 }

Detailed code description:

HTML page:

  //引入微信js文件
   <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/JavaScript">
//配置信息驗(yàn)證接口(填寫的js-sdk獲取的簽名包的參數(shù))
wx.config({
 debug: false,
 appId: &#39;<?PHP echo $signPackage["appId"];?>&#39;,
 timestamp: &#39;<?php echo $signPackage["timestamp"];?>&#39;,
 nonceStr: &#39;<?php echo $signPackage["nonceStr"];?>&#39;,
 signature: &#39;<?php echo $signPackage["signature"];?>&#39;,
 jsApiList: [
  // 所有要調(diào)用的 API 都要加到這個列表中
  &#39;addCard&#39;
  ]
   });
wx.ready(function(){
        //添加卡券
    document.querySelector(&#39;#addCard&#39;).onclick = function () {
     wx.addCard({
      cardList: [
      {
       cardId: "",//微信公眾號內(nèi)創(chuàng)建的會員卡的id
       cardExt: &#39;{"timestamp":"<?php echo $huiyuanPackage[&#39;timestamp&#39;] ?>","signature":"<?php echo $huiyuanPackage[&#39;signature&#39;] ?>"}&#39;//會員卡的簽名包
      }
      ],
     //成功之后的回調(diào)的函數(shù)(通過回調(diào)函數(shù)該表數(shù)據(jù)庫是否領(lǐng)取會員卡的狀態(tài))
      success: function (res) {
      $.ajax({
      url: &#39;__CONTROLLER__/editHuiYuan&#39;,
      type: &#39;post&#39;,
      dataType: &#39;json&#39;,
      data: {is_LingQu: &#39;1&#39;,user_id:"<?php echo $user[&#39;user_id&#39;] ?>"},
      success:function(){
      $("#addCard").html("我的會員卡");
      }
      })
      }
     });
    };
   });
</script>

Code in the controller:

Class library: http://www.jb51.net/article/115732.htm

 public function index(){
 $user_id = session(&#39;user_id&#39;);
  if($user_id){
  $jssdk = new \Home\Model\WechatModel();
  $signPackage = $jssdk->GetSignPackage();//獲取js-sdk簽名包
  $huiyuanPackage = $jssdk->getHuiYuanSignPackage();獲取會員卡簽名包
  //獲取用戶信息 
  $user = M(&#39;user&#39;)->where(array(&#39;user_id&#39; => $user_id))->find();
  //產(chǎn)品收藏數(shù)量統(tǒng)計
  $goods_count = M(&#39;goods_shoucang&#39;)->where(array(&#39;user_id&#39; => $user_id))->count();
  //門店收藏數(shù)量統(tǒng)計
  $shop_count = M(&#39;shop_shoucang&#39;)->where(array(&#39;user_id&#39; => $user_id))->count();
  }else{
  //判斷該用戶是否存在
  $model = new \Home\Model\WechatModel();
  $openid_accesstoken = $model->openId();
  $rst = M(&#39;user&#39;)->where(array(&#39;user_openid&#39; => $openid_accesstoken[&#39;openid&#39;]))->find();
  if($rst){
   session(&#39;openid&#39;,$openid_accesstoken[&#39;openid&#39;]);
   session(&#39;user_id&#39;, $rst[&#39;user_id&#39;]);
   $jssdk = new \Home\Model\WechatModel();
   $signPackage = $jssdk->GetSignPackage();
   $huiyuanPackage = $jssdk->getHuiYuanSignPackage();
   //獲取用戶信息 
   $user = M(&#39;user&#39;)->where(array(&#39;user_id&#39; => $rst[&#39;user_id&#39;]))->find();
   //產(chǎn)品收藏數(shù)量統(tǒng)計
   $goods_count = M(&#39;goods_shoucang&#39;)->where(array(&#39;user_id&#39; => $rst[&#39;user_id&#39;]))->count();
   //門店收藏數(shù)量統(tǒng)計
   $shop_count = M(&#39;shop_shoucang&#39;)->where(array(&#39;user_id&#39; => $rst[&#39;user_id&#39;]))->count();
  }else{
   $userInfo = $model->getOpenId($openid_accesstoken[&#39;openid&#39;],$openid_accesstoken[&#39;access_token&#39;]);
     $data = array(
      &#39;user_img&#39; => $userInfo[&#39;headimgurl&#39;],
      &#39;user_openid&#39; => $userInfo[&#39;openid&#39;],
      &#39;user_name&#39; => filter($userInfo[&#39;nickname&#39;]),
      &#39;user_register_time&#39; => time(),
      &#39;city&#39; => $userInfo[&#39;province&#39;].&#39;-&#39;.$userInfo[&#39;city&#39;],
     );
   $id = M(&#39;user&#39;)->add($data);
   session(&#39;openid&#39;, $userInfo[&#39;openid&#39;]);
   session(&#39;user_id&#39;,$id);
   $jssdk = new \Home\Model\WechatModel();
   $signPackage = $jssdk->GetSignPackage();
   $huiyuanPackage = $jssdk->getHuiYuanSignPackage();
   //獲取用戶信息 
   $user = M(&#39;user&#39;)->where(array(&#39;user_id&#39; => $id))->find();
   //產(chǎn)品收藏數(shù)量統(tǒng)計
   $goods_count = M(&#39;goods_shoucang&#39;)->where(array(&#39;user_id&#39; => $id))->count();
   //門店收藏數(shù)量統(tǒng)計
   $shop_count = M(&#39;shop_shoucang&#39;)->where(array(&#39;user_id&#39; => $id))->count();
   }
  }
  $this->assign(&#39;signPackage&#39;, $signPackage);
  $this->assign(&#39;huiyuanPackage&#39;, $huiyuanPackage);
  $this->assign(&#39;user&#39;, $user);
  $this->assign(&#39;shop_count&#39;, $shop_count);
  $this->assign(&#39;goods_count&#39;, $goods_count);
  $this->display();
 }

The above is the detailed content of Share the WeChat public account to realize the function of receiving membership cards. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Apr 19, 2025 pm 04:51 PM

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

The difference between H5 and mini-programs and APPs The difference between H5 and mini-programs and APPs Apr 06, 2025 am 10:42 AM

H5. The main difference between mini programs and APP is: technical architecture: H5 is based on web technology, and mini programs and APP are independent applications. Experience and functions: H5 is light and easy to use, with limited functions; mini programs are lightweight and have good interactiveness; APPs are powerful and have smooth experience. Compatibility: H5 is cross-platform compatible, applets and APPs are restricted by the platform. Development cost: H5 has low development cost, medium mini programs, and highest APP. Applicable scenarios: H5 is suitable for information display, applets are suitable for lightweight applications, and APPs are suitable for complex functions.

What are the development tools for H5 and mini program? What are the development tools for H5 and mini program? Apr 06, 2025 am 09:54 AM

H5 development tools recommendations: VSCode, WebStorm, Atom, Brackets, Sublime Text; Mini Program Development Tools: WeChat Developer Tools, Alipay Mini Program Developer Tools, Baidu Smart Mini Program IDE, Toutiao Mini Program Developer Tools, Taro.

How to choose H5 and applets How to choose H5 and applets Apr 06, 2025 am 10:51 AM

The choice of H5 and applet depends on the requirements. For applications with cross-platform, rapid development and high scalability, choose H5; for applications with native experience, rich functions and platform dependencies, choose applets.

What are the different ways of promoting H5 and mini programs? What are the different ways of promoting H5 and mini programs? Apr 06, 2025 am 11:03 AM

There are differences in the promotion methods of H5 and mini programs: platform dependence: H5 depends on the browser, and mini programs rely on specific platforms (such as WeChat). User experience: The H5 experience is poor, and the mini program provides a smooth experience similar to native applications. Communication method: H5 is spread through links, and mini programs are shared or searched through the platform. H5 promotion methods: social sharing, email marketing, QR code, SEO, paid advertising. Mini program promotion methods: platform promotion, social sharing, offline promotion, ASO, cooperation with other platforms.

The latest news APP ranking recommendation in the currency circle (authoritative release in 2025) The latest news APP ranking recommendation in the currency circle (authoritative release in 2025) Apr 21, 2025 pm 09:33 PM

The best cryptocurrency trading and analysis platforms include: 1. OKX: the world's number one in trading volume, supports multiple transactions, provides AI market analysis and on-chain data monitoring. 2. Binance: The world's largest exchange, providing in-depth market conditions and new currency first-time offerings. 3. Sesame Open Door: Known for spot trading and OTC channels, it provides automated trading strategies. 4. CoinMarketCap: an authoritative market data platform, covering 20,000 currencies. 5. CoinGecko: Known for community sentiment analysis, it provides DeFi and NFT trend monitoring. 6. Non-small account: a domestic market platform, providing analysis of linkage between A-shares and currency markets. 7. On-chain Finance: Focus on blockchain news and update in-depth reports every day. 8. Golden Finance: 24 small

TikTok web version entrance login link address https TikTok web version entrance website free TikTok web version entrance login link address https TikTok web version entrance website free May 22, 2025 pm 04:24 PM

The login portal for the Douyin web version is https://www.douyin.com/. The login steps include: 1. Open the browser; 2. Enter the URL https://www.douyin.com/; 3. Click the "Login" button and select the login method; 4. Enter the account password; 5. Complete login. The web version provides functions such as browsing, searching, interaction, uploading videos and personal homepage management, and has advantages such as large-screen experience, multi-tasking, convenient account management and data statistics.

What are the scam routines of cryptocurrency exchanges? What are the scam routines of cryptocurrency exchanges? Apr 20, 2025 pm 05:06 PM

10 top scams on cryptocurrency exchanges Common scams: fake exchanges, Ponzi capital trading, contract manipulation, fake coin phishing, customer service fraud, etc. Identification points: Check regulatory licenses, check contract addresses, and be wary of high-yield commitments Must be protected: Use only mainstream exchanges (Binance/Coinbase) Enable hardware wallet Reject share private key/verification code Deal with fraud: take screenshots immediately, freeze assets, report on the platform, and report to the police Core principle: Any request for password/transfer is a fraud!

See all articles