Hbuilder第三方插件开发demo--第三方授权分享支付,推送等
<template>
<view class="content">
<button id="loginByWX" @click="thirdPartyLogin" data-type="weixin">微信第三方登录</button>
<button id="loginByWX" @click="thirdPartyLogin" data-type="qq">QQ第三方登录</button>
<button id="loginByWX" @click="thirdPartyLogin" data-type="sinaweibo">微博第三方登录</button>
<button id="loginByWX" @click="logoutThirdPartyLogin()">退出第三方登录</button>
<button @click="pay" data-id="wxpay">微信pay</button>
<button @click="pay" data-id="alipay">支付宝pay</button>
<button @click="shareHref()">分享</button>
<button @click="dowload">下载</button>
<button @click="getCID">获取CID</button>
<input type="text" :value="device_cid === '' ? '' : device_cid" readonly /> <button @click="innerPush">内推消息</button>
<image src="/static/logo.png" class="logo"></image>
<image class="logo" src="/static/no-image.png"></image>
<view class="text-area">
<text class="title">{{ title }}</text>
</view>
<uni-swipe-action :options="options"><view class="cont">SwipeAction 基础使用场景</view></uni-swipe-action> <uni-pagination total="20"></uni-pagination>
<uni-pagination show-icon="true" total="50" current="2"></uni-pagination>
</view>
</template> <script>
export default {
data() {
return {
title: 'What',
auths: null,
channel: null,
channelArr: {},
ALIPAYSERVER: 'http://demo.dcloud.net.cn/helloh5/payment/alipay.php?total=',
WXPAYSERVER: 'http://demo.dcloud.net.cn/helloh5/payment/wxpay.php?total=',
Intent: null,
File: null,
Uri: null,
main: null,
shares: {},
shareImageUrl: '',
s: null,
device_cid: ''
};
},
onLoad() {
//监听系统通知栏消息点击事件
plus.push.addEventListener(
'click',
function(msg) {
//处理点击消息的业务逻辑代码
var data = plus.push.getAllMessage();
console.log(msg);
plus.push.remove(msg);
},
false
);
//监听接收透传消息事件
plus.push.addEventListener(
'receive',
function(msg) {
//处理透传消息的业务逻辑代码
var data = plus.push.getAllMessage();
console.log(msg);
plus.push.remove(msg);
},
false
); // 1. 获取支付通道
//uni-app中将此function里的代码放入vue页面的onLoad生命周期中
// 获取支付通道
const _this = this;
plus.payment.getChannels(
function(channels) {
_this.channel = channels;
for (var i = 0; i < _this.channel.length; i++) {
//console.log(_this.channel[i].id);
//console.log(_this.channel[i]);
_this.channelArr[_this.channel[i].id] = _this.channel[i];
}
},
function(e) {
uni.showToast({
title: '获取支付通道失败:' + e.message,
duration: 2000
});
}
); //调起分享
this.updateSerivces();
if (plus.os.name == 'Android') {
this.Intent = plus.android.importClass('android.content.Intent');
this.File = plus.android.importClass('java.io.File');
this.Uri = plus.android.importClass('android.net.Uri');
this.main = plus.android.runtimeMainActivity();
}
},
methods: {
//内推消息
innerPush() {
var payload = {};
payload['title'] = '测试内容';
payload['content'] = 'testtesttesttesttesttesttest';
payload['extraKey'] = 'extraKey';
//var payload = { title: '测试', content: 'testtesttesttesttesttesttest', payload: '' };
var option = {};
option['title'] = '测试标题';
plus.push.createMessage('测试内容', payload, option);
},
//获取CID
getCID() {
this.device_cid = plus.push.getClientInfo().clientid;
},
//第三方登录
thirdPartyLogin(e) {
var type = e.currentTarget.dataset.type; const _this = this;
plus.oauth.getServices(
function(services) {
_this.auths = services;
// for (var k in _this.auths) {
// console.log(_this.auths[k].id);
// }
//auths解释0QQ 1微信 2微博 3小米,但是不建议使用auths[1]类似的写法,因为各个设备排序不一样,比较坑爹
//注意获取使用unionid,此id通用后期的微信端等它会用户共享,(openid完全唯一)
//var s = auths[1];
//var s;
for (var i = 0; i < _this.auths.length; i++) {
//用这样的写法指定第三方,参照:
//[LOG] : xiaomi
//[LOG] : qq
//[LOG] : sinaweibo
//[LOG] : weixin
// if (_this.auths[i].id == 'weixin') {
// _this.s = _this.auths[i];
// break;
// }
console.log(type);
if (_this.auths[i].id == type) {
_this.s = _this.auths[i];
break;
} else {
_this.s = null;
}
} if (!_this.s.authResult) {
//授权
//_this.s.authorize(
//function(e) {
//console.log('授权成功:' + JSON.stringify(e));
//登录
_this.s.login(
function(e) {
// 获取登录操作结果
_this.s.getUserInfo(
function(e) {
console.log('获取用户信息成功:' + JSON.stringify(_this.s.userInfo));
uni.showToast({
title: '登录成功',
duration: 2000
});
},
function(e) {
console.log('获取用户信息失败:' + e.message + ' - ' + e.code);
uni.showToast({
title: '获取用户信息失败',
duration: 2000
});
}
);
},
function(e) {
uni.showToast({
title: '登录认证失败',
duration: 2000
});
}
);
//},
//function(e) {
// plus.nativeUI.alert('授权失败:' + JSON.stringify(e));
//},
//{ scope: 'snsapi_userinfo', state: 'authorize_test', appid: 'wx289c8964c0689011' }
//);
} else {
//已经登录认证
uni.showToast({
title: '登录成功',
duration: 2000
});
}
},
function(e) {
console.log('获取登录失败:' + e.message + ' - ' + e.code);
uni.showToast({
title: '登录认证失败',
duration: 2000
});
}
);
}, //退出第三方登录
logoutThirdPartyLogin() {
var thirdLogin = this.s;
if (!thirdLogin) {
plus.nativeUI.alert('当前环境不支持第三方登录');
return;
}
thirdLogin.logout(
function(e) {
plus.nativeUI.alert('注销登录认证成功!');
},
function(e) {
plus.nativeUI.alert('注销登录认证失败: ' + JSON.stringify(e));
}
);
}, // 支付-------发起支付请求
pay(e) {
// 从服务器请求支付订单
console.log(e.currentTarget.dataset.id);
var id = e.currentTarget.dataset.id;
var PAYSERVER = '';
if (id == 'alipay') {
PAYSERVER = this.ALIPAYSERVER;
} else if (id == 'wxpay') {
PAYSERVER = this.WXPAYSERVER;
} else {
plus.nativeUI.alert('不支持此支付通道!', null, '捐赠');
return;
}
console.log(this.channelArr[id]);
uni.request({
url: PAYSERVER, //仅为示例,并非真实接口地址。
method: 'GET',
//data: { text: 'uni.request' },
// header: {
// 'custom-header': 'hello' //自定义请求头信息
// },
success: res => {
console.log(res.data);
if (res.data.status == 200) {
plus.payment.request(
this.channelArr[id],
res.data.data,
function(result) {
plus.nativeUI.alert('支付成功!', function() {
back();
});
},
function(error) {
plus.nativeUI.alert('支付失败:' + error.code);
}
);
} else {
uni.showToast({
title: '获取订单信息失败!',
duration: 2000
});
}
}
});
}, //分享----分享按钮点击事件
shareHref() {
var ids = [
{
id: 'weixin',
ex: 'WXSceneSession' /*微信好友*/
},
{
id: 'weixin',
ex: 'WXSceneTimeline' /*微信朋友圈*/
},
{
id: 'qq' /*,QQ好友*/,
ex: ''
},
{
id: 'tencentweibo' /*,腾讯微博*/,
ex: ''
},
{
id: 'sinaweibo' /*,新浪微博*/,
ex: ''
}
],
bts = [
{
title: '发送给微信好友'
},
{
title: '分享到微信朋友圈'
},
{
title: '分享到QQ'
},
{
title: '分享到腾讯微博'
},
{
title: '分享到新浪微博'
}
];
const _this = this;
plus.nativeUI.actionSheet(
{
cancel: '取消',
buttons: bts
},
function(e) {
var i = e.index;
if (i > 0) {
_this.shareAction(ids[i - 1].id, ids[i - 1].ex);
}
}
);
},
/**
* 更新分享服务
*/
updateSerivces() {
const _this = this;
plus.share.getServices(
function(s) {
for (var i in s) {
var t = s[i];
_this.shares[t.id] = t;
}
uni.showToast({
title: '获取分享服务列表成功!',
duration: 2000
});
},
function(e) {
console.log(e.message);
uni.showToast({
title: '获取分享服务列表失败:' + e.message,
duration: 2000
});
}
);
},
/**
* 分享操作
*/
shareAction(id, ex) {
var s = null;
if (!id || !(s = this.shares[id])) {
uni.showToast({
title: '无效的分享服务!',
duration: 2000
});
return;
}
if (s.authenticated) {
uni.showToast({
title: '---已授权---',
duration: 2000
});
this.shareMessage(s, ex);
} else {
uni.showToast({
title: '---未授权---',
duration: 2000
});
const _this = this;
s.authorize(
function() {
_this.shareMessage(s, ex);
},
function(e) {
uni.showToast({
title: '认证授权失败',
duration: 2000
});
}
);
}
},
/**
* 发送分享消息
*/
shareMessage(s, ex) {
var msg = {
content: '分享-详情',
href: 'http://www.baidu.com',
title: '分享测试-title',
content: '分享测试-content',
thumbs: ['http://img3.3lian.com/2013/v10/4/87.jpg'],
pictures: ['http://img3.3lian.com/2013/v10/4/87.jpg'],
extra: {
scene: ex
}
};
s.send(
msg,
function() {
uni.showToast({
title: '分享成功!',
duration: 2000
});
},
function(e) {
uni.showToast({
title: '分享失败!',
duration: 2000
});
}
);
}, //下载
//dtask =null;
//检查是否含有该文件
// feach() {
// var FileSystemURL = '_downloads/kkkk123.zip';
// plus.io.resolveLocalFileSystemURL(
// FileSystemURL,
// function() {
// this.dowload('http://172.16.120.156:2345/download-pic');
// },
// function() {
// console.log('未找到文件');
// }
// );
// },
//下载文件
dowload() {
var options = { method: 'GET', filename: '/download/a.zip' };
var dtask = null;
dtask = plus.downloader.createDownload('http://172.16.120.156:2345/download-pic', options);
dtask.addEventListener('statechanged', function(task, status) {
switch (task.state) {
case 1: // 开始
console.log('开始下载...');
break;
case 2: // 已连接到服务器
console.log('链接到服务器...');
break;
case 3: // 已接收到数据
var a = Math.floor((task.downloadedSize / task.totalSize) * 100) + '%';
console.log(a);
break;
case 4: // 下载完成
console.log('下载完成!');
console.log(task.totalSize);
plus.io.resolveLocalFileSystemURL(task.filename, function(entry) {
console.log(entry.toLocalURL()); //绝对地址
});
console.log(task.filename);
break;
}
});
dtask.start();
},
// 暂停下载任务
pauseDownloadTask() {
dtask.pause(); //暂停下载
},
// 恢复下载任务
resumeDownloadTask() {
dtask.resume(); //恢复下载
}
}
};
</script> <style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
} .logo {
height: 200upx;
width: 200upx;
margin-top: 200upx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50upx;
} .text-area {
display: flex;
justify-content: center;
} .title {
font-size: 36upx;
color: #8f8f94;
}
</style>
Hbuilder第三方插件开发demo--第三方授权分享支付,推送等的更多相关文章
- Android高效率编码-第三方SDK详解系列(三)——JPush推送牵扯出来的江湖恩怨,XMPP实现推送,自定义客户端推送
Android高效率编码-第三方SDK详解系列(三)--JPush推送牵扯出来的江湖恩怨,XMPP实现推送,自定义客户端推送 很久没有更新第三方SDK这个系列了,所以更新一下这几天工作中使用到的推送, ...
- python微信服务号关注授权、消息推送流程
阅读目录 推送的方式: 微信推送的流程: 流程分析: 给用户推送消息功能 推送的方式: 短信推送(第三方) 邮件推送 微信推送 公众号:认证的公众号(个人的认证公众号每天只能发一篇文章),粉丝可以跟公 ...
- iOS无处不在详解iOS集成第三方登录(SSO授权登录无需密码)
链接地址:http://www.it165.net/pro/html/201408/18884.html 1.前言 不多说,第三登录无处不在!必备技能,今天以新浪微博为例. 这是上次写的iOS第三方社 ...
- iOS- 无处不在,详解iOS集成第三方登录(SSO授权登录<无需密码>)
1.前言 不多说,第三登录无处不在!必备技能,今天以新浪微博为例. 这是上次写的iOS第三方社交分享:http://www.cnblogs.com/qingche/p/3727559.html 可 ...
- 钉钉开发第三方H5微应用入门详细教程[ISV][免登流程][授权码][HTTP回调推送][识别用户身份][获取用户信息]
转载请注明原文地址:https://www.cnblogs.com/applerosa/p/11509512.html (by lnexin@aliyun.com 世间草木) 此教程注意点: 适用于第 ...
- Vue/小程序/小程序云+Node+Mongo开发微信授权、支付和分享
大家好,我是河畔一角,今天给大家介绍我的第三门实战课程:基于微信开发的H5.小程序和小程序云的授权.支付和分享专项课程. 一.这一次为什么会选择微信支付和分享的课题呢? 金庸的小说中曾提到:有人的地方 ...
- 【原创分享·微信支付】C# MVC 微信支付之微信模板消息推送
微信支付之微信模板消息推送 今天我要跟大家分享的是“模板消息”的推送,这玩意呢,你说用途嘛,那还是真真的牛逼呐.原因在哪?就是因为它是依赖微信生存的呀,所以他能不 ...
- Android高效率编码-第三方SDK详解系列(二)——Bmob后端云开发,实现登录注册,更改资料,修改密码,邮箱验证,上传,下载,推送消息,缩略图加载等功能
Android高效率编码-第三方SDK详解系列(二)--Bmob后端云开发,实现登录注册,更改资料,修改密码,邮箱验证,上传,下载,推送消息,缩略图加载等功能 我的本意是第二篇写Mob的shareSD ...
- iOS应用第三方推送的添加
现在的一些第三方的推送平台挺好用,主要是因为他们有类似微信公众平台一样的管理后台,简单易用,封装了很多开发者需要的推送功能. 下面以个推为例: 1.在个推的应用配置iOS部分设置自己的BounleID ...
随机推荐
- tycho 打包编译报错 Access restriction: The type XYZ is not API
解决办法: 在pom.xml中加入以下配置 <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId ...
- 如何使用python异常---runtimeError方法
RuntimeError def ilove(name): if name=='陈培昌': print('i love {0}'.format(name)) elif name == '程劲': pr ...
- for迭代多个对象
1.传统方法 from random import randint chinese = [randint(60, 100) for _ in range(40)] math = [randint(60 ...
- Centos7下Nexus3的安装和配置
参考文档:https://help.sonatype.com/repomanager3 1.要使用nexus服务需要安装jdk和maven 1.1.jdk下载地址:https://www.oracle ...
- java web项目为什么我们要放弃jsp?(转)
前戏: 以前的项目大多数都是java程序猿又当爹又当妈,又搞前端(ajax/jquery/js/html/css等等),又搞后端(java/mysql/Oracle等等). 随着时代的发展,渐渐的许多 ...
- Kafka 消息队列系列之分布式消息队列Kafka
介绍 ApacheKafka®是一个分布式流媒体平台.这到底是什么意思呢?我们认为流媒体平台具有三个关键功能:它可以让你发布和订阅记录流.在这方面,它类似于消息队列或企业消息传递系统.它允许您以容 ...
- loj#6285 数列分块入门 9 ( 回 滚 )
题目 : 链接 :https://loj.ac/problem/6285 题意:给出一个长为 n的数列,以及 n个操作,操作涉及询问区间的最小众数. 思路:虽然这不是一道 回滚莫队题,就是 暴力分块 ...
- ActiveMQ C#实例
重点参考:NMS Documentation 一.ActiveMQ Queue 在ActiveMQ中Queue是一种点对点的消息分发方式,生产者在队列中添加一条消息,然后消费者消费一条消息,这条消息保 ...
- jumpserver官方手动安装
测试环境 CPU: 64位双核处理器 内存: 4G DDR3 数据库:mysql 版本大于等于 5.6 mariadb 版本大于等于 5.5.6 环境 系统: CentOS 7 IP: 192.168 ...
- c++示例 计算器
#include <iostream> using namespace std; int main() { char op; float num1, num2; cout << ...