文章目录

  • 1 需求描述
  • 2 系统分享
    • 2.1 Html关键代码
    • 2.2 JavaScript脚本关键代码
    • 2.3 界面效果
  • 3 FaceBook分享
    • 3.1 多语言配置
    • 3.2 后台关键代码
    • 3.3 参数约定
    • 3.4 数据落地
    • 3.5 测试地址
    • 3.6 分享效果
  • 4 如何跳转APP内

1 需求描述

​ A用户分享游戏链接给B用户,B用户如果已经下载该游戏则唤醒app,没有则会根据不同的机型跳到不同的商店如安卓进入安卓应用商店,ios进入app store 。因为浏览器和app没有通信协议,所以h5不知道用户的手机释放安装了app,只能是h5去尝试唤起app,若不能唤起,引导用户去下载我们的app。具体需求如下:

  1. 系统分享页面加载完后直接跳转到下载链接。
  2. UGC相关分享先试图打开游戏跳转到对应的关卡但是用户不一定安装游戏,所以接下来跳转下载链接。
  3. 统计PV和Click事件。

2 系统分享

​ 系统分享页面加载完后直接跳转相应的下载链接。

2.1 Html关键代码

<!DOCTYPE html>
<html>
<head><title>Bricks Ball Crusher</title><meta name='description' content='Bricks Ball Crusher'/><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/><meta name='viewport'content='width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1'/><meta property='og:locale' content='en_US'/><meta property='og:type' content='website'/><meta property='og:image' content='img/edit.png'/><meta property='og:image:type' content='image/jpeg'/><meta property='og:url' content='/'/><meta property='og:site_name' content='Bricks Ball Crusher'/><meta property='fb:app_id' content=''/><meta property='og:title' content="I've created an interesting level.Come and have a try."/><meta property='og:description' content="Try the level I created."/><script src='js/jquery.min.js'></script><link rel='stylesheet' href='css/bootstrap.min.css'><style>* {margin: 0;padding: 0;font-family: '微软雅黑'}body {background: url(img/bg.png);background-size: cover;background-attachment: fixed;}</style>
</head>
<body>
<div class='container'><!--标题 开始 --><div class='row'><img src='img/title.png' class='img-responsive center-block'/></div><!--标题 开始 --><!--主宣传图 开始 --><div class='row' style='margin-top: -110px'><img src='img/main.png' class='img-responsive center-block'/></div><!--主宣传图 开始 --><!--副标题 开始 --><div class='row' style='margin: 30px 30px 10px 10px'><img src='img/subtitle.png' class='img-responsive center-block'></div><!--副标题 开始 --><!--下载按钮 开始 --><table class='table table-no-bordered' style='border:0px;'><tr><td style='border:0px'><img src='img/goole.png' class='img-responsive center-block download '></td><td style='border:0px'><img src='img/appstore.png' class='img-responsive center-block download ' style='padding-left:10px'></td></tr></table><!--下载按钮 结束 -->
</div>
</body>
</html>

2.2 JavaScript脚本关键代码

<script type='text/javascript'>function openApp(which, arg) {//此处以打开淘宝为例jumpApp('taobao://');noApp();}function jumpApp(t) {window.location.href = t;}var timer = null;function noApp() {var t = Date.now(),timer = setTimeout(function() {return Date.now() - t > 2200? (clearTimeout(timer), !1): !document.webkitHidden && !document.hidden && void (location.href = "下载链接");}, 2000);}$('.download').click(function () {//向后台发送请求$.get('http://ip:port/share/click?type=find');noApp();});  noApp();
</script>

2.3 界面效果

3 FaceBook分享

Facebook分享需要按照他们的要求填写一些Meta信息具体如下:

<meta property='og:site_name' content='Bricks Ball Crusher' />
<meta property='fb:app_id' content='' />
<meta property='og:title' content="I've created an interesting level.Come and have a try." />
<meta property='og:description' content="Try the level I created." />
<meta property='og:url' content='/' />
<meta property='og:image' content='' />
<meta property='og:image:type' content='image/jpeg' />
<meta property='og:locale' content='en_US' />
<meta property='og:type' content='website' />

不同场景下:图片不同则需要修改og:image的值;标题不同需要修改og:title的值;描述不同需要修改og:description的值。

3.1 多语言配置

游戏中语言肯定不止一种,玩家分享时需要根据系统语言获取相应的分享内容。

## 英文结果页分享
en_invite_title=Come and play bricks in the Bricks Ball Crusher with me!
en_invite_description=Come and play bricks in the Bricks Ball Crusher with me!
en_invite_img_url=img/invite.png
## 英文UGC创造分享
en_edit_title=I've created an interesting level.Come and have a try.
en_edit_description =Try the level I created.
en_edit_img_url=img/edit.png
## 英文UGC分享别人关卡
en_find_title=Let's try this interesting level together.
en_find_description =Click here to join us
en_find_img_url=img/find.png
## 中文结果页分享
zh_cn_invite_title=全民消砖块
zh_cn_invite_description=快来和我一起在全民消砖块里一起打砖块吧
zh_cn_invite_img_url=img/invite.png
## 中文UGC创造分享
zh_cn_edit_title=和我一起体验创造关卡的乐趣
zh_cn_edit_description =我在全民消砖块创建了一个有趣的关卡,快来试试吧
zh_cn_edit_img_url=img/edit.png
## 中文UGC分享别人关卡
zh_cn_find_title=这是一个有趣的关卡
zh_cn_find_description =我在全民消砖块发现了一个有趣的关卡,快来和我一起挑战一下吧
zh_cn_find_img_url=img/find.png
## 中文繁体结果页分享
zh_tw_invite_title=全民消磚塊
zh_tw_invite_description=快來和我一起在全民消磚塊裏一起打磚塊吧
zh_tw_invite_img_url=img/invite.png
## 中文繁体UGC创造分享
zh_tw_edit_title=和我一起體驗創造關卡的樂趣
zh_tw_edit_description =我在全民消磚塊創建了一個有趣的關卡,快來試試吧
zh_tw_edit_img_url=img/invite.png
## 中文繁体UGC分享别人关卡
zh_tw_find_title=這是一個有趣的關卡
zh_tw_find_description =我在全民消磚塊發現了一個有趣的關卡,快來和我一起挑戰一下吧
zh_tw_find_img_url=img/find.png
## 日文结果页分享
jp_invite_title=是非、レンガボール粉砕機で私と一緒にレンガをプレイ!
jp_invite_description=是非、レンガボール粉砕機で私と一緒にレンガをプレイ!
jp_invite_img_url=img/invite.png
## 日文UGC创造分享
jp_edit_title=私は面白いを作成しました来てください試してみてください。
jp_edit_description =私が作成したレベルをお試しください。
jp_edit_img_url=img/edit.png
## 日文UGC分享别人关卡
jp_find_title=一緒にこの面白いレベルを試してみましょう。
jp_find_description=ここをクリック
jp_find_img_url=img/find.png
## 俄文结果页分享
ru_invite_title=Давай поиграем со мной в кирпичную дробилку
ru_invite_description=Давай поиграем со мной в кирпичную дробилку
ru_invite_img_url=img/invite.png
## 俄文UGC创造分享
ru_edit_title=Я создал веселье.уровень, давайПопробуй.
ru_edit_description =попробуйте создать заставу.
ru_edit_img_url=img/edit.png
## 俄文UGC分享别人关卡
ru_find_title=Давайте попробуем этот интересный пункт.
ru_find_description =Нажмите здесь чтобы добавить нас
ru_find_img_url=img/find.png
## 韩文结果页分享
kr_invite_title=나 랑 같이 벽돌공 파 쇄 기 하 자.
kr_invite_description=나 랑 같이 벽돌공 파 쇄 기 하 자.
kr_invite_img_url=img/invite.png
## 韩文UGC创造分享
kr_edit_title=제 가 재 밌 는 걸 만 들 었 어 요.수준.해 봐.
kr_edit_description =내 가 세운 관문 을 시험 해 봐.
kr_edit_img_url=https:img/edit.png
## 韩文UGC分享别人关卡
kr_find_title=우리 함께 이 재 미 있 는 관문 을 시험 해 봅 시다.
kr_find_description =여기에 가입 하려 면 누 르 십시오
kr_find_img_url=img/find.png

3.2 后台关键代码

该功能为根据不同的分享内容,动态的修改og:image、og:title、og:description的值;当type为invite时访问该链接页面加载完后跳转下载地址,否则先试图启动游戏再跳转到下载地址;统计PV和click事件。

import com.pusidun.common.utils.DateUtils;
import com.pusidun.common.utils.IPUtils;
import com.pusidun.common.utils.StringUtils;
import com.pusidun.modules.generator.entity.ShareEntity;
import com.pusidun.modules.generator.service.ShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Date;
@RestController
public class ShareController {@Autowiredprivate Environment env; //读取环境变量@Autowiredprivate ShareService shareService;/*** 分享功能* @param  type 三种分享类型分别为: invite edit find* @param  hl 六种语言分别为:en zh_cn zh_tw jp ru kr* @param  id  当type=create或者find时,该参数必传* @param  res 响应*/@RequestMapping(value = "/share/{type}",  produces={"application/json; charset=UTF-8"})public void sharePage( HttpServletRequest request, HttpServletResponse res,@PathVariable String type, @RequestParam String hl,String id) throws UnsupportedEncodingException{saveShareData(request,"show",type);//数据上报if(StringUtils.isEmpty(type))   type="invite";if(StringUtils.isEmpty(hl)) hl="en";String urlSchema = "taobao://";if(StringUtils.isNotEmpty(id))  urlSchema = "bxb://level="+id;String titleKey=  hl+"_"+type+"_title";String descriptionKey= hl+"_"+type+"_description";String imgUrlKey = hl+"_"+type+"_img_url";String title=  new String(env.getProperty(titleKey.toLowerCase()).getBytes("ISO8859-1"),"UTF-8");String description= new String(env.getProperty(descriptionKey.toLowerCase()).getBytes("ISO8859-1"),"UTF-8");String img_url = new String(env.getProperty(imgUrlKey.toLowerCase()).getBytes("ISO8859-1"),"UTF-8");try {res.setContentType("text/html; charset=UTF-8");//注意text/html,和application/htmlString html ="<!DOCTYPE html>\n" +"<html>\n" +"<head>\n" +"<title>Bricks Ball Crusher</title>\n" +"<meta name='description' content='Bricks Ball Crusher' />\n" +"<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />\n" +"<meta name='viewport' content='width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1' />\n" +"<meta property='og:locale' content='en_US' />\n" +"<meta property='og:type' content='website' />\n" +"<meta property='og:image' content='"+img_url+"' />\n" +"<meta property='og:image:type' content='image/jpeg' />\n" +"<meta property='og:url' content='/' />\n" +"<meta property='og:site_name' content='Bricks Ball Crusher' />\n" +"<meta property='fb:app_id' content='' />\n" +"<meta property='og:title' content=\""+title+"\" />\n" +"<meta property='og:description' content=\""+description+"\" />\n" +"<script src='js/jquery.min.js'></script>\n" +"<link rel='stylesheet' href='css/bootstrap.min.css'>\n" +"<style>\n" +"* {margin:0; padding:0;font-family:'微软雅黑'}\n" +"body {background:url(img/bg.png); background-size:cover; background-attachment: fixed;}\n" +"</style>\n" +"</head>\n" +"<body >\n" +"<div class='container' >\n" +"<!--标题 开始 -->\n" +"<div class='row' >\n" +"<img src='img/title.png'  class='img-responsive center-block' />\n" +"</div>\n" +"<!--标题 开始 -->\n" +"<!--主宣传图 开始 -->\n" +"<div class='row' style='margin-top: -110px'>\n" +"<img src='img/main.png'  class='img-responsive center-block' />\n" +"</div>\n" +"<!--主宣传图 开始 -->\n" +"<!--副标题 开始 -->\n" +"<div class='row' style='margin: 30px 30px 10px 10px'>\n" +"<img src='img/subtitle.png' class='img-responsive center-block'>\n" +"</div>\n" +"<!--副标题 开始 -->\n" +"<!--下载按钮 开始 -->\n" +"<table   class='table table-no-bordered' style='border:0px;' >\n" +"<tr>\n" +"<td style='border:0px' ><img src='img/goole.png'    class='img-responsive center-block download ' ></td>\n" +"<td style='border:0px' ><img src='img/appstore.png' class='img-responsive center-block download ' style='padding-left:10px'></td>\n" +"</tr>\n" +"</table>\n" +"<!--下载按钮 结束 -->\n" +"</div>\n" +"<script type='text/javascript'>\n" +"function openApp(which, arg) {\n" +"    jumpApp('"+urlSchema+"');\n" +"    noApp();\n" +"}\n" +"function jumpApp(t) {\n" +"  window.location.href = t;\n" +"}\n" +"var timer = null;\n" +"function noApp() {\n" +"  var t = Date.now(),\n" +"  timer = setTimeout(function() {\n" +"    return Date.now() - t > 2200\n" +"      ? (clearTimeout(timer), !1)\n" +"      : !document.webkitHidden && !document.hidden && void (location.href = '下载地址');\n" +"  }, 2000);\n" +"}\n" +"$('.download').click(function () {\n" +"//向后台发送请求\n" +"$.get('http://ip:port/share/click?type="+type+"');\n" +"noApp();\n" +"}); ";if("invite".equals(type)){html += " noApp();</script> </body> </html>";}else {html += " openApp();</script> </body> </html>";}res.getWriter().print(html);res.getWriter().close();} catch (IOException e) {e.printStackTrace();}}/*** 分享点击按钮* @param request 请求*/@RequestMapping(value = "share/click",  produces={"application/json; charset=UTF-8"})public void shareClick(HttpServletRequest request,String type){saveShareData(request,"click",type);}/*** 写入数据库* @param request 请求* @param eventName 事件名*/private void saveShareData(HttpServletRequest request,String eventName,String uri){ShareEntity entity = new ShareEntity();entity.setIp(IPUtils.getIpAddr(request));entity.setEventName(eventName);entity.setSessionId(request.getRequestedSessionId());entity.setTime(DateUtils.format(new Date(),DateUtils.DATE_TIME_PATTERN));entity.setUri(uri);shareService.save(entity);}
}

3.3 参数约定

参数约定
type: invite edit find
hl:系统语言,统一小写 en zh_cn zh_tw jp ru kr
id:关卡id

3.4 数据落地

3.5 测试地址

https://developers.facebook.com/tools/debug

3.6 分享效果

4 如何跳转APP内

URL Scheme就是一个可以让app相互之间可以跳转的对外接口。通过给APP定义一个唯一的URL路径来从外部快速的打开这个指定的APP,每个app的URL Scheme都是不一样的,如果存在一样的URL Scheme,那么系统就会响应先安装那个app的URL Scheme,因为后安装的app的URL Scheme被覆盖掉了,是不能被调用的。URL scheme的格式是 :

[scheme] ://[host]/[path]?[query]

介绍几个常用的URL Scheme平台:

  • QQ: mqq://
  • 微信: weixin://
  • 腾讯微博: TencentWeibo://
  • 淘宝: taobao://
  • 支付宝: alipay://
  • 微博: sinaweibo://

游戏如何分享到Facebook点击链接启动游戏相关推荐

  1. 过亿月流水H5游戏优化分享、腾讯自研H5游戏优化分享、Layabox官方优化分享,全在这里了!...

    非常抱歉,小编整理的大神干货分享来晚了,今天的文章献给Layabox的游戏开发者.感谢Layabox开发者沙龙的分享嘉宾们,带来了非常干货的优化经验,小编只是干货分享的搬运工. 火爆的深圳与广州站La ...

  2. linux上安装游戏程序,分享|如何在 Linux 中安装 2048 游戏

    流行的移动益智游戏 2048 也可以在 Ubuntu 和 Linux 发行版上玩.啊!你甚至可以在 Linux 终端上玩 2048.如果你的生产率因为这个让人上瘾的游戏下降,请不要怪我. 早在 201 ...

  3. 点击链接启动钉钉微应用(带参数)

    一.参考官方文档 https://developers.dingtalk.com/document/app/message-link-description 二.划线部分是要改的地方,这个路径指的是开 ...

  4. js 年会大屏_年会H5大屏互动游戏案例分享

    原标题:年会H5大屏互动游戏案例分享 利用h5制作年会互动小游戏越来越火爆了,今天小编就给大家推荐两个年会h5案例,希望能给大家的设计带来灵感,参考网站:hui.cdlchd.com. 案例一:201 ...

  5. 玩游戏什么品牌蓝牙耳机延迟低?高性价比游戏专属蓝牙耳机推荐

    游戏耳机,顾名思义就是专门为游戏而设的一个耳机种类,一款好的游戏耳机对于玩家来说,能够给我们提供一种身临其境的感觉,而且还能给玩家起到极大的辅助作用,游戏体验也因此提升.如今想要舒适安逸的体验自然非蓝 ...

  6. python编的游戏越玩越卡_用Python写游戏,不到十分钟就学会了

    安装pygame 本人电脑是windows 10.python3.6,pygame下载地址:pypi.python.org/pypi/Pygame- 请自行下载对应python版本的pygame 运行 ...

  7. python游戏代码运行不了_用Python写游戏,不到十分钟就学会了

    安装pygame 请自行下载对应python版本的pygame 运行以下命令 创建Pygame窗口及响应用户输入 新建一个文件夹alien_invasion,并在文件夹中新建alien_invasio ...

  8. 计算机链接手机网络游戏,怎么用手机玩Wegame电脑游戏 Wegame手机玩电脑游戏方法分享...

    大家都知道wegame的新功能是可以让玩家在手机上玩电脑游戏,那么wegame在手机上怎么玩电脑游戏?怎么设置呢?这边91手游网小编给大家介绍下吧 Wegame手机玩电脑游戏方法分享 官方介绍 PS4 ...

  9. Java多线程游戏实例分享2-雷火(手把手教你做个超炫酷的星际争霸)

    观前提示: 本文涉及的小成果特别多,即使你不需要写一个和我完全相同的游戏,也可以按照需要查看某些特定功能的实现过程,说不定能够给您的程序开发带来一点小小的启发!PS:结合源代码阅读此博客更加高效. 本 ...

最新文章

  1. 路由协议重分发之RIP协议和EIGEP协议
  2. python编程if语法-Python编程入门基础语法详解经典
  3. 人脸识别基础关键技术
  4. JAVA进阶开发之(二维数组)
  5. android 修改listview item view 的方法(转)
  6. Java 9 ← 2017,2019 → Java 13 ,来看看Java两年来的变化
  7. 素材干货|UI设计师不会插画?不难搞!有了这些模板,作品安了!
  8. java static 变量,和方法从属于类
  9. js空格占位符_灵活使用 console 让 js 调试更简单
  10. MATLAB实现频数直方图——hist的使用
  11. CSS font-family字体大合集
  12. jmeter性能测试~Beanshell
  13. MFC基于对话框程序启动时隐藏窗口的实现
  14. clappr:可扩展网页媒体播放器使用
  15. C++默认参数(缺省参数)应该写在哪里,声明还是定义里
  16. 全民投资人游戏服务器维护,欢乐园《全民仙战》2月3日14时合服公告
  17. uni-app中的生命周期钩子函数
  18. vscode 中 django基本操作
  19. JVM学习(三)JVM内存模型
  20. ABP框架引入easyUI

热门文章

  1. ABB机器人线速度_ABB机器人新示教器创建工具工件坐标系
  2. Ehcache(缓存)
  3. java基础学习 day28(就近原则,this关键字,构造方法,标准Javabean类)
  4. 绝地求生服务器维护9月19日,绝地求生9月19日维护到几点_绝地求生9月19日维护内容介绍_快吧单机游戏...
  5. WSDL UDDI
  6. HP M1005打印问题
  7. 松迪机器人_-CIROS机器人展
  8. js 问号点操作符 (可选链 双问号)
  9. mate10支持html,华为mate10能升级到EMUI10吗 EMUI10支持华为mate10吗
  10. 第一单元计算机基础知识,第一单元 计算机基础知识 第一课资料