- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章php一个文件搞定微信jssdk配置由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
php一个文件搞定微信jssdk配置:
包括缓存,包括https通讯,获取微信access_token,签名什么的都有。但是防范性编程做得比较少,商业用的话,需要完善下代码.
使用姿势 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
^ajax(Common.ServerUrl +
"GetWX.php"
, {
data: {
Type:
"config"
,
url: location.href.split(
'#'
)[0]
},
dataType:
'json'
,
type:
'get'
,
timeout: 5000,
success:
function
(data) {
wx.config({
debug: true,
// 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId:
'……'
,
// 必填,公众号的唯一标识
timestamp: data.timestamp,
// 必填,生成签名的时间戳
nonceStr: data.nonceStr,
// 必填,生成签名的随机串
signature: data.signature,
// 必填,签名,见附录1
jsApiList: [
"getLocation"
]
// 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
}
})
wx.ready(
function
() {
wx.getLocation({
type:
'wgs84'
,
// 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success:
function
(res) {
var
latitude = res.latitude;
// 纬度,浮点数,范围为90 ~ -90
var
longitude = res.longitude;
// 经度,浮点数,范围为180 ~ -180。
plus2.storage.setItem(
"latitude"
, latitude);
plus2.storage.setItem(
"longitude"
, longitude);
}
});
});
|
服务端 。
GetWX.php 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
<?php
include
"lib/Cache.php"
;
define(
$APPID
,
"……"
);
define(
$SECRET
,
"……"
)
if
(
$_GET
[
'Type'
] ==
"access_token"
){
// echo getAccess_token();
}
else
if
(
$_GET
[
'Type'
] ==
"jsapi_ticket"
){
// echo getJsapi_ticket();
}
else
if
(
$_GET
[
'Type'
] ==
"config"
){
$jsapi_ticket
= getJsapi_ticket();
$nonceStr
=
"x"
.rand(10000,100000).
"x"
;
//随机字符串
$timestamp
= time();
//时间戳
$url
=
$_GET
[
'url'
];
$signature
= getSignature(
$jsapi_ticket
,
$nonceStr
,
$timestamp
,
$url
);
$result
=
array
(
"jsapi_ticket"
=>
$jsapi_ticket
,
"nonceStr"
=>
$nonceStr
,
"timestamp"
=>
$timestamp
,
"url"
=>
$url
,
"signature"
=>
$signature
);
echo
json_encode(
$result
);
}
function
getSignature(
$jsapi_ticket
,
$noncestr
,
$timestamp
,
$url
){
$string1
=
"jsapi_ticket="
.
$jsapi_ticket
.
"&noncestr="
.
$noncestr
.
"×tamp="
.
$timestamp
.
"&url="
.
$url
;
$sha1
= sha1(
$string1
);
return
$sha1
;
}
function
getJsapi_ticket(){
$cache
=
new
Cache();
$cache
=
new
Cache(7000,
'cache/'
);
//需要创建cache文件夹存储缓存文件。
//从缓存从读取键值 $key 的数据
$jsapi_ticket
=
$cache
-> get(
"jsapi_ticket"
);
$access_token
= getAccess_token();
//如果没有缓存数据
if
(
$jsapi_ticket
== false) {
$access_token
= getAccess_token();
$url
=
'https://api.weixin.qq.com/cgi-bin/ticket/getticket'
;
$data
=
array
(
'type'
=>
'jsapi'
,
'access_token'
=>
$access_token
);
$header
=
array
();
$response
= json_decode(curl_https(
$url
,
$data
,
$header
, 5));
$jsapi_ticket
=
$response
->ticket;
//写入键值 $key 的数据
$cache
-> put(
"jsapi_ticket"
,
$jsapi_ticket
);
}
return
$jsapi_ticket
;
}
function
getAccess_token(){
$cache
=
new
Cache();
$cache
=
new
Cache(7000,
'cache/'
);
//从缓存从读取键值 $key 的数据
$access_token
=
$cache
-> get(
"access_token"
);
//如果没有缓存数据
if
(
$access_token
== false) {
$url
=
'https://api.weixin.qq.com/cgi-bin/token'
;
$data
=
array
(
'grant_type'
=>
'client_credential'
,
'appid'
=>
$APPID
,
'secret'
=>
$SECRET
);
$header
=
array
();
$response
= json_decode(curl_https(
$url
,
$data
,
$header
, 5));
$access_token
=
$response
->access_token;
//写入键值 $key 的数据
$cache
-> put(
"access_token"
,
$access_token
);
}
return
$access_token
;
}
/** curl 获取 https 请求
* @param String $url 请求的url
* @param Array $data 要發送的數據
* @param Array $header 请求时发送的header
* @param int $timeout 超时时间,默认30s
*/
function
curl_https(
$url
,
$data
=
array
(),
$header
=
array
(),
$timeout
=30){
$ch
= curl_init();
curl_setopt(
$ch
, CURLOPT_SSL_VERIFYPEER, false);
// 跳过证书检查
curl_setopt(
$ch
, CURLOPT_URL,
$url
);
curl_setopt(
$ch
, CURLOPT_HTTPHEADER,
$header
);
curl_setopt(
$ch
, CURLOPT_POST, true);
curl_setopt(
$ch
, CURLOPT_POSTFIELDS, http_build_query(
$data
));
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$ch
, CURLOPT_TIMEOUT,
$timeout
);
$response
= curl_exec(
$ch
);
if
(
$error
=curl_error(
$ch
)){
die
(
$error
);
}
curl_close(
$ch
);
return
$response
;
}
?>
|
Cache.php 不知道哪位写的源代码~ 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
<?php
class
Cache {
private
$cache_path
;
//path for the cache
private
$cache_expire
;
//seconds that the cache expires
//cache constructor, optional expiring time and cache path
public
function
Cache(
$exp_time
= 3600,
$path
=
"cache/"
) {
$this
-> cache_expire =
$exp_time
;
$this
-> cache_path =
$path
;
}
//returns the filename for the cache
private
function
fileName(
$key
) {
return
$this
-> cache_path . md5(
$key
);
}
//creates new cache files with the given data, $key== name of the cache, data the info/values to store
public
function
put(
$key
,
$data
) {
$values
= serialize(
$data
);
$filename
=
$this
-> fileName(
$key
);
$file
=
fopen
(
$filename
,
'w'
);
if
(
$file
) {
//able to create the file
fwrite(
$file
,
$values
);
fclose(
$file
);
}
else
return
false;
}
//returns cache for the given key
public
function
get(
$key
) {
$filename
=
$this
-> fileName(
$key
);
if
(!
file_exists
(
$filename
) || !
is_readable
(
$filename
)) {
//can't read the cache
return
false;
}
if
(time() < (
filemtime
(
$filename
) +
$this
-> cache_expire)) {
//cache for the key not expired
$file
=
fopen
(
$filename
,
"r"
);
// read data file
if
(
$file
) {
//able to open the file
$data
=
fread
(
$file
,
filesize
(
$filename
));
fclose(
$file
);
return
unserialize(
$data
);
//return the values
}
else
return
false;
}
else
return
false;
//was expired you need to create new
}
}
?>
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
最后此篇关于php一个文件搞定微信jssdk配置的文章就讲到这里了,如果你想了解更多关于php一个文件搞定微信jssdk配置的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
当有人使用微信(微信)分享我的一款游戏(用 JavaScript 制作)时,我正在使用 WeixinJSBridge 修改分享参数。 下面的代码位于一个很大的 JavaScript 文件(超过 250
我转微信了padplus来自wechaty-puppet-puppeteer的傀儡并发现它比 wechaty-puppet-puppeteer 更频繁地停止.即,wechaty-puppet-pupp
微信小程序一出,立马炸开了锅,都去搭建自己的开发环境,我这里也来尝尝先,之前发了一篇文章,有人问demo怎么导入? demo源代码(来自网络) 百度: https://pan.baidu.com
微信小程序可谓是今天最火的一个名词了,一经出现真是轰炸了整个开发人员,当然很多app开发人员有了一个担心,微信小程序的到来会不会给移动端app带来一个寒冬,身为一个android开发者我是不相信的,
memcache缓存存储用户信息7000秒 ? 1
微信开发生成带参数的二维码的讲解 在微信公众号平台开发者那里,在“账号管理”那里,有一项功能是“生成带参数的二维码”,通过这儿生成的二维码,只要通过微信扫一扫之后,会把事件自动推送到微信公众号上
某日,一同学给小的发了 Github 源码,说是可以轻松查到删除自己的微信好友,于是就开始了作死之路。 Github 源码请看:0x5e/wechat-deleted-friends 前言
近段时间山西的连续降雨,不少的城市都出现了洪灾,救灾物资匮乏,不少明星及爱心人士都纷纷向山西捐款,那么目前来说山西捐款的通道有哪些呢?在支付宝,微信上如何给山西捐款呢?下面就和小编一起来看看山西捐款
一.集成支付宝支付 支付宝集成官方教程 https://docs.open.alipay.com/204/105295/ 支付宝集成官方demo https://docs.o
一.越来越多的app增加第三方的功能,可能app有不同的页面但调用相同的支付方式,例如界面如下: 这两个页面都会使用第三方支付支付:(微信,支付宝,银联)如果在每一个页面都直接调用第三方支付的
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我安装了一个虚假的位置应用程序并将我的位置设置为不同的位置。然后打开谷歌地图和微信应用, Google map 将我的位置显示为我设置的(假的) 微信应用忽略虚假位置并检测真实位置(如何?) 然后我想
前言 支付分APP支付、H5支付、扫码支付等。app支付一般在app中使用,并且需要集成相应的支付SDK,H5支付多用于网页。如果你的APP不想集成支付SDK,又想实现支付功能,你可以在项目中使用
最近一直在调用微信的api,却发现一直调用不成功,纠结了好久,各方面找教程,找官方,官方里的文档也只是写得很模糊,说是按三步走。 1、申请app_id 2、填写包名3、 获取程序签
和平精英QQ/微信 每日登陆抽奖1~188Q币 活动两个QQ和微信都可以 每天登陆游戏并且玩一局 然后可以去活动界面抽奖Q币 QQ端(需玩一局):http://t.cn/Ai1Jn7Tz
目前,当我使用带有 Link 插件的 TinyMce4.5.1 时。即使我将属性 link_list 设置为 false,我也找不到隐藏默认 URL 选项(#top、#bottom)的方法。除了破
实际上,我正在尝试使用微信为我的 Web 应用程序设置 OAuth 登录。所以,我在微信上创建了一个帐户,并使用了一个测试帐户来无限访问。 因此,在测试帐户配置中,我已成功验证来自微信的 token
不管是腾讯还是新浪,查看他们的API,PHP都是有完整的接口,但对C#支持似乎都不是那么完善,都没有,腾讯是完全没有,新浪是提供第三方的,而且后期还不一定升级,NND,用第三方的动辄就一个类库,各种
和平精英QQ/微信 每日登陆抽奖1~188Q币/现金红包 活动两个QQ和微信都可以 QQ的登录游戏和分享好友即可获得三次抽奖次数 微信登录游戏就可以抽奖 如果没有反应就分享链接出去从分享的链接进
我想做什么 我正在尝试将我自己的基于 WebGL 的引擎移植到微信小游戏环境,目前只是尝试让 WebGL 上下文被粉红色清除: 有什么问题 我已经按照腾讯提供的示例以及 ThreeJS 示例来设置游戏
我是一名优秀的程序员,十分优秀!