CN110704786B - 一种限制微信转发的方法 - Google Patents

一种限制微信转发的方法 Download PDF

Info

Publication number
CN110704786B
CN110704786B CN201910966171.2A CN201910966171A CN110704786B CN 110704786 B CN110704786 B CN 110704786B CN 201910966171 A CN201910966171 A CN 201910966171A CN 110704786 B CN110704786 B CN 110704786B
Authority
CN
China
Prior art keywords
wechat
page
forwarding
openid
web server
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910966171.2A
Other languages
English (en)
Other versions
CN110704786A (zh
Inventor
邱文乔
黄修海
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuxi Anteng Software Development Co ltd
Original Assignee
Wuxi Anteng Software Development Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuxi Anteng Software Development Co ltd filed Critical Wuxi Anteng Software Development Co ltd
Priority to CN201910966171.2A priority Critical patent/CN110704786B/zh
Publication of CN110704786A publication Critical patent/CN110704786A/zh
Application granted granted Critical
Publication of CN110704786B publication Critical patent/CN110704786B/zh
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/958Organisation or management of web site content, e.g. publishing, maintaining pages or automatic linking
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/62Protecting access to data via a platform, e.g. using keys or access control rules
    • G06F21/6209Protecting access to data via a platform, e.g. using keys or access control rules to a single file or object, e.g. in a secure envelope, encrypted and accessed using a key, or with access control rules appended to the object itself

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • General Health & Medical Sciences (AREA)
  • Computer Hardware Design (AREA)
  • Computer Security & Cryptography (AREA)
  • Software Systems (AREA)
  • Health & Medical Sciences (AREA)
  • Bioethics (AREA)
  • Data Mining & Analysis (AREA)
  • Storage Device Security (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

本发明公开了一种限制微信转发的方法,包括:步骤一,构建一台用于存储用户需要分享的页面的WEB服务器及数据库,并且注册一个微信公众号;步骤二,生成跳转页面;步骤三,在数据库中创建一张表,字段至少需要包含“url”和”openid”;当用户成功分享跳转页面后,WEB服务器将页面的实际链接填入url字段中;步骤四,获取code,并跳转到实际的url地址;步骤五,获取openid;步骤六,比较、填入openid;步骤七,获取用于屏蔽掉页面的转发按钮的access_token,然后获取jsapi_ticket;步骤八,生成签名字符串;步骤九,将步骤八中的noncestr、timestamp、signature传给页面,进行微信右上角转发按钮的隐藏操作。本发明可以实现页面与第一个查看的人的微信号相绑定,打开之后禁止进行转发。

Description

一种限制微信转发的方法
技术领域
本发明涉及一种限制微信转发的方法。
背景技术
如今微信的使用已经越来越广泛,很多商务场合也经常用微信来交互文件、网页。比如发报价单、产品样例等。但是对方在收到这些资料后,往往会转发给第三方。现有的解决方案是将文件转为网页页面。然后经过一段时间之后将此页面删除。或者设定这个页面可以访问的次数。但是因为无法确定用户,所以可能存在,用户看完之后立即转发给其他人,或者用户还想在看的时候,经过页面已经删除了。无论是方便性还是实用性,都有很大的缺陷。用户更需要的是,禁止微信转发,如果万一真的转发,也要能够禁止打开。
发明内容
本发明的目的是提供一种限制微信转发的方法,实现页面与第一个查看的人的微信号相绑定,打开之后禁止进行转发。
实现本发明目的的技术方案是:一种限制微信转发的方法,包括以下步骤:
步骤一,构建一台用于存储用户需要分享的页面的WEB服务器及数据库,并且注册一个微信公众号;
步骤二,当用户将WEB服务器中的一个页面分享给微信用户时,WEB服务器另外生成一个跳转页面,该跳转页面中写入如下脚本:
<script>
var authUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxx&redirect_uri="+被分享页面的实际链接+"&response_type=code&scope=snsapi_userinfo&state=#wechat_redirect";window.location.href=authUrl;
</script>
其中,appid为步骤一注册的微信公众号的ID;
步骤三,在数据库中创建一张表,字段至少需要包含“url”和”openid”;当用户成功分享跳转页面后,WEB服务器将页面的实际链接填入url字段中;
步骤四,当接收方通过微信打开收到的链接时,根据页面中的脚本,将首先跳出一个授权认证的页面;当接收方点击同意后,微信将会自动根据跳转页面脚本中的redirect_uri信息,发出一个访问请求到WEB服务器,并且在访问请求中的页面实际链接中增加一个code参数;
步骤五,WEB服务器在微信发送的访问请求中得到code值,然后向微信请求获取接收方的openid;
步骤六,将获取到的微信接收方的openid与数据库对应的记录中的字段openid进行比较;若数据库对应的记录中的字段openid没有值,表明这是第一次打开,则将获取到的微信接收方的openid填入此字段;若有值,则进行比较,若相同,则表明还是这个接收方在打开页面,否则是其他用户,则拒绝显示页面;
步骤七,获取用于屏蔽掉页面的转发按钮的access_token,然后获取jsapi_ticket;
步骤八,随机生成的noncestr字符串,然后将noncestr字符串、当前时间戳timestamp、当前页面url、步骤七获取到的jsapi_ticket拼接成字符串,最后将该字符串以SHA1算法加密得到signature签名字符串;
步骤九,将步骤八中的noncestr、timestamp、signature传给页面,页面调用微信apiwx.config进行权限验证,验证成功后调用wx.hideMenuItemsapi进行微信右上角转发按钮的隐藏操作,实现对微信转发的限制。
进一步地,所述步骤五中向微信请求获取微信接收方的openid的具体方法为:
向微信请求以下链接:
https://api.weixin.qq.com/sns/oauth2/access_token?appid=xxx&secret=xxx&code=CODE&grant_type=authorization_code;
其中,appid和secret的值在步骤一注册的微信公众号中查询;
请求后,微信将会以json格式返回一串数据,其中包括openid,解析此字段,即可得到需要的openid值。
进一步地,所述步骤七中通过以下链接获取用于屏蔽掉页面的转发按钮的access_token:
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=xxx&secret=xxx,其中appid和secret的值在步骤一注册的微信公众号中查询。
进一步地,所述步骤七中通过以下链接获取jsapi_ticket:
https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=xxx&type=jsapi。
进一步地,所述步骤八中拼接字符串的规则为:
"jsapi_ticket="+jsapi_ticket+"&noncestr="+noncestr+"&timestamp="+timestamp+"&url="+url。
采用了上述技术方案,本发明具有以下的有益效果:本发明可以实现页面与第一个查看的人的微信号相绑定,打开之后禁止进行转发。如果用某些特殊的方法进行的转发,对方在收到之后,也无法打开页面。
具体实施方式
(实施例1)
本实施例的限制微信转发的方法,包括以下步骤:
步骤一,构建一台用于存储用户需要分享的页面的WEB服务器(如IIS、apache)及数据库(如sqlserver、oracle、mysql),并且注册一个微信公众号;
步骤二,当用户将WEB服务器中的一个页面(如http://www.mydomain.com/myurl&param=a)分享给微信用户时,WEB服务器另外生成一个跳转页面(http://www.mydomain/com/myjump&id=xxx),该跳转页面中写入如下脚本:
<script>
var authUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxx&redirect_uri="+http://www.mydomain.com/myurl&param=a+"&response_type=code&scope=snsapi_userinfo&state=#wechat_redirect";window.location.href=authUrl;
</script>
其中,mydomain.com为WEB服务器的域名,appid为步骤一注册的微信公众号的ID;
步骤三,在数据库中创建一张表,字段至少需要包含“url(链接地址)”和”openid(微信的识别ID)”;当用户成功分享跳转页面后,WEB服务器将页面的实际链接(http://www.mydomain.com/myurl&param=a)填入url字段中;
步骤四,当接收方通过微信打开收到的链接时,根据页面中的脚本(https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxx),将首先跳出一个授权认证的页面;当接收方点击同意后,微信将会自动根据跳转页面脚本中的redirect_uri信息,发出一个访问请求到WEB服务器,并且在访问请求中的页面实际链接中增加一个code参数(即实际将请求:http://www.mydomain.com/myurl&param=a&code=xxxxxx);
步骤五,WEB服务器在微信发送的访问请求中得到code值,向微信请求以下链接:
https://api.weixin.qq.com/sns/oauth2/access_token?appid=xxx&secret=xxx&code=CODE&grant_type=authorization_code;其中,appid和secret的值在步骤一注册的微信公众号中查询;
请求后,微信将会以json格式返回一串数据,形如:
Figure BDA0002230541490000041
其中包括openid,解析此字段,即可得到需要的openid值。
步骤六,将获取到的微信接收方的openid与数据库对应的记录中的字段openid进行比较;若数据库对应的记录中的字段openid没有值,表明这是第一次打开,则将获取到的微信接收方的openid填入此字段;若有值,则进行比较,若相同,则表明还是这个接收方在打开页面,否则是其他用户,则拒绝显示页面;
步骤七,通过以下链接获取用于屏蔽掉页面的转发按钮的access_token:
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=xxx&secret=xxx,其中appid和secret的值在步骤一注册的微信公众号中查询;
再通过以下链接获取jsapi_ticket:
https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=xxx&type=jsapi。
步骤八,随机生成的noncestr字符串,然后将noncestr字符串、当前时间戳timestamp、当前页面url、步骤七获取到的jsapi_ticket拼接成字符串,最后将该字符串以SHA1算法加密得到signature签名字符串;拼接字符串的规则为:
"jsapi_ticket="+jsapi_ticket+"&noncestr="+noncestr+"&timestamp="+timestamp+"&url="+url。
步骤九,将步骤八中的noncestr、timestamp、signature传给页面,页面调用微信apiwx.config进行权限验证,验证成功后调用wx.hideMenuItemsapi进行微信右上角转发按钮的隐藏操作,实现对微信转发的限制。
以上所述的具体实施例,对本发明的目的、技术方案和有益效果进行了进一步详细说明,所应理解的是,以上所述仅为本发明的具体实施例而已,并不用于限制本发明,凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。

Claims (5)

1.一种限制微信转发的方法,其特征在于:包括以下步骤:
步骤一,构建一台用于存储用户需要分享的页面的WEB服务器及数据库,并且注册一个微信公众号;
步骤二,当用户将WEB服务器中的一个页面分享给微信用户时,WEB服务器另外生成一个跳转页面,该跳转页面中写入如下脚本:
<script>
var authUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxx&redirect_uri="+被分享页面的实际链接+"&response_type=code&scope=snsapi_userinfo&state=#wechat_redirect";
window.location.href=authUrl;
</script>
其中,appid为步骤一注册的微信公众号的ID;
步骤三,在数据库中创建一张表,字段至少需要包含“url”和”openid”;当用户成功分享跳转页面后,WEB服务器将页面的实际链接填入url字段中;
步骤四,当接收方通过微信打开收到的链接时,根据页面中的脚本,将首先跳出一个授权认证的页面;当接收方点击同意后,微信将会自动根据跳转页面脚本中的redirect_uri信息,发出一个访问请求到WEB服务器,并且在访问请求中的页面实际链接中增加一个code参数;
步骤五,WEB服务器在微信发送的访问请求中得到code值,然后向微信请求获取微信接收方的openid;
步骤六,将获取到的微信接收方的openid与数据库对应的记录中的字段openid进行比较;若数据库对应的记录中的字段openid没有值,表明这是第一次打开,则将获取到的微信接收方的openid填入此字段;若有值,则进行比较,若相同,则表明还是这个接收方在打开页面,否则是其他用户,则拒绝显示页面;
步骤七,获取用于屏蔽掉页面的转发按钮的access_token,然后获取jsapi_ticket;
步骤八,随机生成的noncestr字符串,然后将noncestr字符串、当前时间戳timestamp、当前页面url、步骤七获取到的jsapi_ticket拼接成字符串,最后将该字符串以SHA1算法加密得到signature签名字符串;
步骤九,将步骤八中的noncestr、timestamp、signature传给页面,页面调用微信apiwx.config进行权限验证,验证成功后调用wx.hideMenuItemsapi进行微信右上角转发按钮的隐藏操作,实现对微信转发的限制。
2.根据权利要求1所述的一种限制微信转发的方法,其特征在于:所述步骤五中向微信请求获取微信接收方的openid的具体方法为:
向微信请求以下链接:
https://api.weixin.qq.com/sns/oauth2/access_token?appid=xxx&secret=xxx&code=CODE&grant_type=authorization_code;
其中,appid和secret的值在步骤一注册的微信公众号中查询;
请求后,微信将会以json格式返回一串数据,其中包括openid,解析此字段,即可得到需要的openid值。
3.根据权利要求1所述的一种限制微信转发的方法,其特征在于:所述步骤七中通过以下链接获取用于屏蔽掉页面的转发按钮的access_token:
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=xxx&secret=xxx,其中appid和secret的值在步骤一注册的微信公众号中查询。
4.根据权利要求1所述的一种限制微信转发的方法,其特征在于:所述步骤七中通过以下链接获取jsapi_ticket:
https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=xxx&type=jsapi。
5.根据权利要求1所述的一种限制微信转发的方法,其特征在于:所述步骤八中拼接字符串的规则为:
"jsapi_ticket="+jsapi_ticket+"&noncestr="+noncestr+"&timestamp="+timestamp+"&url="+url。
CN201910966171.2A 2019-10-12 2019-10-12 一种限制微信转发的方法 Active CN110704786B (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910966171.2A CN110704786B (zh) 2019-10-12 2019-10-12 一种限制微信转发的方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910966171.2A CN110704786B (zh) 2019-10-12 2019-10-12 一种限制微信转发的方法

Publications (2)

Publication Number Publication Date
CN110704786A CN110704786A (zh) 2020-01-17
CN110704786B true CN110704786B (zh) 2022-04-05

Family

ID=69198508

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910966171.2A Active CN110704786B (zh) 2019-10-12 2019-10-12 一种限制微信转发的方法

Country Status (1)

Country Link
CN (1) CN110704786B (zh)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106961332A (zh) * 2016-01-11 2017-07-18 腾讯科技(深圳)有限公司 一种权限认证方法及装置
CN108256897A (zh) * 2017-12-25 2018-07-06 平安科技(深圳)有限公司 基于h5活动页面传播的营销方法、电子装置及存储介质
CN109525656A (zh) * 2018-11-07 2019-03-26 四川长虹电器股份有限公司 一种实现不关注微信公众号预获取用户喜好的方法

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120185920A1 (en) * 2011-01-13 2012-07-19 International Business Machines Corporation Serialized authentication and authorization services

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106961332A (zh) * 2016-01-11 2017-07-18 腾讯科技(深圳)有限公司 一种权限认证方法及装置
CN108256897A (zh) * 2017-12-25 2018-07-06 平安科技(深圳)有限公司 基于h5活动页面传播的营销方法、电子装置及存储介质
CN109525656A (zh) * 2018-11-07 2019-03-26 四川长虹电器股份有限公司 一种实现不关注微信公众号预获取用户喜好的方法

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
高校教务微信公众平台应用研究;苏家莉;《佳木斯职业学院学报》;20171231(第5期);第263-264页 *

Also Published As

Publication number Publication date
CN110704786A (zh) 2020-01-17

Similar Documents

Publication Publication Date Title
US10110584B1 (en) Elevating trust in user identity during RESTful authentication and authorization
CN106063219B (zh) 用于生物识别协议标准的系统和方法
US10110579B2 (en) Stateless and secure authentication
Josang et al. Usability and privacy in identity management architectures
Chadwick Federated identity management
US9225690B1 (en) Browser security module
US8819253B2 (en) Network message generation for automated authentication
US7685631B1 (en) Authentication of a server by a client to prevent fraudulent user interfaces
US11336686B2 (en) Electronic authentication infrastructure
US8051465B1 (en) Mitigating forgery of electronic submissions
US11714693B2 (en) Data driven API conversion
US20030061515A1 (en) Capability-enabled uniform resource locator for secure web exporting and method of using same
AU2016331050A1 (en) System and method for using a symbol as instruction to initiate transfer of authenticated mobile identity information
US9313257B2 (en) Method for starting a client program
TW201019676A (en) Identity and authentication system using aliases
US9003540B1 (en) Mitigating forgery for active content
WO2003049000A1 (en) Distributed network identity
US9479533B2 (en) Time based authentication codes
Ferry et al. Security evaluation of the OAuth 2.0 framework
US10616209B2 (en) Preventing inter-application message hijacking
US20160212123A1 (en) System and method for providing a certificate by way of a browser extension
US9053297B1 (en) Filtering communications
Al-Sinani et al. CardSpace-Liberty integration for CardSpace users
Chadwick et al. The trusted attribute aggregation service (TAAS)-providing an attribute aggregation layer for federated identity management
Close Web-key: Mashing with permission

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant