
uni.getLocation偶而获取不到,使用原生代码替换
在APP中一直使用uni.getLocation的系统定位模块获取模糊位置,用以查询同城文章。偶然发现最近升级代码后,ANDROID下uni.getLocation无法正常工作,返回error:2错误。在仔细检查后,怀疑是hbuilderx升级后的BUG。写了一段android原生代码工作正常,并在运行一次此代码获取到位置后,再使用uni.getLocation即能正常。有理由怀疑是uni.getLocation使用了getLastKnownLocation导致的,查android文档,getLastKnownLocation返回最近一次位置缓存,并不保证时效及是否有值。所以在运行这段代码后,缓存了位置值,此后uni.getLocation可以正常动作。
这是一段试验代码,并未加入超时、错误和权限检查等功能,只用于临时替换及检验uni.getLocation是否正常工作。
PS:时间原故未做更多研究,不确定是否是BUG,厂家有结果请予以告知。
__getLocation = (options) => {
const p = new Promise((resolve, reject) => {
const isNull = value => !value && reject({
errMsg: "_getLocation fail."
});
isNull(options);
isNull(options.success);
isNull(typeof options.success === "function");
const mainActivity = plus.android.runtimeMainActivity();
isNull(mainActivity);
const LOCATION_SERVICE = plus.android.getAttribute(mainActivity, "LOCATION_SERVICE");
const locationManager = plus.android.invoke(mainActivity, "getSystemService",
LOCATION_SERVICE);
plus.android.autoCollection(mainActivity);
isNull(locationManager);
const criteria = plus.android.newObject("android.location.Criteria");
isNull(criteria);
const ACCURACY_COARSE = criteria.plusGetAttribute("ACCURACY_COARSE");
plus.android.invoke(criteria, "setAccuracy", ACCURACY_COARSE);
plus.android.invoke(criteria, "setAltitudeRequired", false);
plus.android.invoke(criteria, "setBearingRequired", false);
plus.android.invoke(criteria, "setCostAllowed", false);
const POWER_LOW = criteria.plusGetAttribute("POWER_LOW");
plus.android.invoke(criteria, "setPowerRequirement", POWER_LOW);
const provider = plus.android.invoke(locationManager, "getBestProvider", criteria, true);
plus.android.autoCollection(criteria);
isNull(provider);
const location = plus.android.invoke(locationManager, "getLastKnownLocation", provider);
////怀疑是此处无值导致原函数错误
if (location) {
const longitude = plus.android.invoke(location, "getLongitude");
const latitude = plus.android.invoke(location, "getLatitude");
plus.android.autoCollection(location);
resolve({
longitude,
latitude
});
} else {
////location无值则进行监听至有值返回
let instLocationListener = null;
const locationListener = {
"onLocationChanged": function(location) {
if (location) {
const longitude = plus.android.invoke(location, "getLongitude");
const latitude = plus.android.invoke(location, "getLatitude");
plus.android.invoke(locationManager, "removeUpdates",
instLocationListener);
plus.android.autoCollection(instLocationListener);
plus.android.autoCollection(location);
resolve({
longitude,
latitude
});
}
},
"onStatusChanged": function(provider, status, extras) {
console.log(provider, status);
},
"onProviderEnabled": function(provider) {
console.log(provider + " 启用了");
},
"onProviderDisabled": function(provider) {
console.log(provider + " 关闭了");
}
}
instLocationListener = plus.android.implements("android.location.LocationListener",
locationListener);
isNull(instLocationListener);
plus.android.invoke(locationManager, "requestLocationUpdates", provider,
3000, 10,
instLocationListener);
}
});
p.then(res => options.success(res)).catch(err => options.fail && options.fail(err));
};
__getLocation({
success: res => console.log(res)
});
在APP中一直使用uni.getLocation的系统定位模块获取模糊位置,用以查询同城文章。偶然发现最近升级代码后,ANDROID下uni.getLocation无法正常工作,返回error:2错误。在仔细检查后,怀疑是hbuilderx升级后的BUG。写了一段android原生代码工作正常,并在运行一次此代码获取到位置后,再使用uni.getLocation即能正常。有理由怀疑是uni.getLocation使用了getLastKnownLocation导致的,查android文档,getLastKnownLocation返回最近一次位置缓存,并不保证时效及是否有值。所以在运行这段代码后,缓存了位置值,此后uni.getLocation可以正常动作。
这是一段试验代码,并未加入超时、错误和权限检查等功能,只用于临时替换及检验uni.getLocation是否正常工作。
PS:时间原故未做更多研究,不确定是否是BUG,厂家有结果请予以告知。
__getLocation = (options) => {
const p = new Promise((resolve, reject) => {
const isNull = value => !value && reject({
errMsg: "_getLocation fail."
});
isNull(options);
isNull(options.success);
isNull(typeof options.success === "function");
const mainActivity = plus.android.runtimeMainActivity();
isNull(mainActivity);
const LOCATION_SERVICE = plus.android.getAttribute(mainActivity, "LOCATION_SERVICE");
const locationManager = plus.android.invoke(mainActivity, "getSystemService",
LOCATION_SERVICE);
plus.android.autoCollection(mainActivity);
isNull(locationManager);
const criteria = plus.android.newObject("android.location.Criteria");
isNull(criteria);
const ACCURACY_COARSE = criteria.plusGetAttribute("ACCURACY_COARSE");
plus.android.invoke(criteria, "setAccuracy", ACCURACY_COARSE);
plus.android.invoke(criteria, "setAltitudeRequired", false);
plus.android.invoke(criteria, "setBearingRequired", false);
plus.android.invoke(criteria, "setCostAllowed", false);
const POWER_LOW = criteria.plusGetAttribute("POWER_LOW");
plus.android.invoke(criteria, "setPowerRequirement", POWER_LOW);
const provider = plus.android.invoke(locationManager, "getBestProvider", criteria, true);
plus.android.autoCollection(criteria);
isNull(provider);
const location = plus.android.invoke(locationManager, "getLastKnownLocation", provider);
////怀疑是此处无值导致原函数错误
if (location) {
const longitude = plus.android.invoke(location, "getLongitude");
const latitude = plus.android.invoke(location, "getLatitude");
plus.android.autoCollection(location);
resolve({
longitude,
latitude
});
} else {
////location无值则进行监听至有值返回
let instLocationListener = null;
const locationListener = {
"onLocationChanged": function(location) {
if (location) {
const longitude = plus.android.invoke(location, "getLongitude");
const latitude = plus.android.invoke(location, "getLatitude");
plus.android.invoke(locationManager, "removeUpdates",
instLocationListener);
plus.android.autoCollection(instLocationListener);
plus.android.autoCollection(location);
resolve({
longitude,
latitude
});
}
},
"onStatusChanged": function(provider, status, extras) {
console.log(provider, status);
},
"onProviderEnabled": function(provider) {
console.log(provider + " 启用了");
},
"onProviderDisabled": function(provider) {
console.log(provider + " 关闭了");
}
}
instLocationListener = plus.android.implements("android.location.LocationListener",
locationListener);
isNull(instLocationListener);
plus.android.invoke(locationManager, "requestLocationUpdates", provider,
3000, 10,
instLocationListener);
}
});
p.then(res => options.success(res)).catch(err => options.fail && options.fail(err));
};
__getLocation({
success: res => console.log(res)
});
收起阅读 »

找一个懂安卓原生+uniapp插件包兼职开发
需要做一个安卓原生插件包,供uniapp原生代码调用;
主要需求: 自定义扫条码样式功能、自定义扫二维码样式功能、个别特定原生实现需求提供API供uniapp调用。
需要做一个安卓原生插件包,供uniapp原生代码调用;
主要需求: 自定义扫条码样式功能、自定义扫二维码样式功能、个别特定原生实现需求提供API供uniapp调用。

如何在GitHub免费搭建个人博客网站?
如何在GitHub免费搭建个人博客网站?当你想要开始自己的博客之旅,但又不想花费金钱购买服务器和域名时,还有一些免费的平台可供你选择。以下是一种无需服务器和域名的方法,利用GitHub Pages和Jekyll搭建个人博客网站(http://m.bokequ.com/list/22-0.html)

步骤一:准备 GitHub 账户
如果你还没有 GitHub 账户,首先需要注册一个。GitHub 提供免费的代码托管服务,同时也支持通过 GitHub Pages 托管静态网站。
步骤二:创建 GitHub 仓库
登录你的 GitHub 账户,点击右上角的加号按钮,选择 "New repository"。在 "Repository name" 栏中输入你的用户名(或者你希望的博客地址),比如 yourusername.github.io(注意替换成你的用户名)。勾选 "Initialize this repository with a README" 选项,并点击 "Create repository"。
步骤三:下载 Jekyll 主题
Jekyll 是一个简单易用的静态网站生成器,GitHub Pages 支持使用 Jekyll 搭建个人网站。你可以在 Jekyll 官方网站(https://jekyllrb.com/)或 GitHub 上找到各种免费的 Jekyll 主题。选择一个你喜欢的主题,将其下载并解压缩到本地。
步骤四:上传文件到 GitHub 仓库
将 Jekyll 主题文件夹中的所有文件上传到你在步骤二中创建的 GitHub 仓库中。你可以使用 GitHub Desktop、Git 命令行或者直接通过 GitHub 网站上传文件。
步骤五:访问你的博客网站
等待一段时间,GitHub 会自动构建你的网站,并将其托管在bokequ.github.io这个地址上。你可以在浏览器中输入这个地址,访问你的个人博客网站。
步骤六:定制你的博客
编辑 Jekyll 主题文件夹中的配置文件和内容文件,定制你的个人博客。你可以修改页面布局、添加新的页面和文章,以及调整样式和颜色。
通过 GitHub Pages 和 Jekyll,你可以免费搭建个人博客网站,无需购买服务器和域名。这是一个简单且经济高效的方式,让你能够开始你的博客之旅,并与世界分享你的想法和创作。
如何在GitHub免费搭建个人博客网站?当你想要开始自己的博客之旅,但又不想花费金钱购买服务器和域名时,还有一些免费的平台可供你选择。以下是一种无需服务器和域名的方法,利用GitHub Pages和Jekyll搭建个人博客网站(http://m.bokequ.com/list/22-0.html)
步骤一:准备 GitHub 账户
如果你还没有 GitHub 账户,首先需要注册一个。GitHub 提供免费的代码托管服务,同时也支持通过 GitHub Pages 托管静态网站。
步骤二:创建 GitHub 仓库
登录你的 GitHub 账户,点击右上角的加号按钮,选择 "New repository"。在 "Repository name" 栏中输入你的用户名(或者你希望的博客地址),比如 yourusername.github.io(注意替换成你的用户名)。勾选 "Initialize this repository with a README" 选项,并点击 "Create repository"。
步骤三:下载 Jekyll 主题
Jekyll 是一个简单易用的静态网站生成器,GitHub Pages 支持使用 Jekyll 搭建个人网站。你可以在 Jekyll 官方网站(https://jekyllrb.com/)或 GitHub 上找到各种免费的 Jekyll 主题。选择一个你喜欢的主题,将其下载并解压缩到本地。
步骤四:上传文件到 GitHub 仓库
将 Jekyll 主题文件夹中的所有文件上传到你在步骤二中创建的 GitHub 仓库中。你可以使用 GitHub Desktop、Git 命令行或者直接通过 GitHub 网站上传文件。
步骤五:访问你的博客网站
等待一段时间,GitHub 会自动构建你的网站,并将其托管在bokequ.github.io这个地址上。你可以在浏览器中输入这个地址,访问你的个人博客网站。
步骤六:定制你的博客
编辑 Jekyll 主题文件夹中的配置文件和内容文件,定制你的个人博客。你可以修改页面布局、添加新的页面和文章,以及调整样式和颜色。
通过 GitHub Pages 和 Jekyll,你可以免费搭建个人博客网站,无需购买服务器和域名。这是一个简单且经济高效的方式,让你能够开始你的博客之旅,并与世界分享你的想法和创作。
收起阅读 »
favicon.ico图片在线制作PHP源码分享
【在线ICO图标制作】Favicon.ico图片在线制作网站。favicon.ico一般用于作为缩略的网站标志,它显示位于浏览器的地址栏或者在标签上,用于显示网站的logo,如图红圈的位置, 目前主要的浏览器都支持favicon.ico图标http://www.bokequ.com/580.html
【在线ICO图标制作】Favicon.ico图片在线制作网站。favicon.ico一般用于作为缩略的网站标志,它显示位于浏览器的地址栏或者在标签上,用于显示网站的logo,如图红圈的位置, 目前主要的浏览器都支持favicon.ico图标http://www.bokequ.com/580.html
收起阅读 »
uni.getSystemInfoSync() 返回参数:locationEnabled,总是true
文档说是地理位置的系统开关是否打开。但用户在关闭定位权限情况下也返回true。
文档说是地理位置的系统开关是否打开。但用户在关闭定位权限情况下也返回true。

uniCloud 外部系统联登 注册功能 C# 完整示例
APP端
this.$http
.post(`/uniCloudRegister`, {
clientInfo:JSON.stringify(uni.getSystemInfoSync())
})
.then(res =>{
uni.stopPullDownRefresh()
uni.hideNavigationBarLoading()
console.info(res)
}).catch(err => {
console.error(err)
uni.stopPullDownRefresh()
uni.hideNavigationBarLoading()
})
后台接口 UserController:ApiController
ConstantsConstants//业务系统登录后才需要联登到 uniCloud,所以不需要在注册时执行,而是单独给出了注册功能的接口
[HttpPost]
[Route("uniCloudRegister")]
public async Task<HttpResponseMessage> uniCloudRegister([FromBody] UniClient client)
{
HttpResponseMessage response = null;
try
{
//此为验证当前系统token并转为 user类的工具,这里就不给出详细示例了
var ui = JwtHelper.AnalysisToken(HttpContext.Current.Request);
//见 Utils
string uniAppUserName = Utils.GetExternalUid(ui);
string nonce = Utils.GetNonce();
// 获取当前时间戳(精确到毫秒)
long timestamp = Utils.GetNowTimeStamp();
Dictionary<string, string> paramsDictionary = new Dictionary<string, string>
{
{ "externalUid", uniAppUserName},
{ "nickname", ui.Name},
};
//签名算法见 Utils
string signature = Utils.GetSignature(paramsDictionary, nonce, timestamp);
//client.clientInfo 为JSON.stringify(uni.getSystemInfoSync()) 这里再转回json对象
var cliInfo = JsonConvert.DeserializeObject<JObject>(client.clientInfo);
Dictionary<string, object> param = new Dictionary<string, object>();
param.Add("clientInfo", cliInfo);
param.Add("uniIdToken", "");
param.Add("params", paramsDictionary);
// 将对象序列化为JSON字符串
string jsonContent = JsonConvert.SerializeObject(param);
Dictionary<string, string> headers = new Dictionary<string, string>()
{
{"uni-id-nonce",nonce },
{"uni-id-timestamp",timestamp + ""},
{"uni-id-signature",signature}
};
var res = await HttpHelper.SendPostAsync(Constants.PushRegister, jsonContent, headers);
if (res.Count > 0)
{
response = Request.CreateResponse(System.Net.HttpStatusCode.OK, res);
}
else
{
response = Request.CreateResponse(System.Net.HttpStatusCode.BadRequest, "error");
}
}
catch (Exception ex)
{
response = Request.CreateErrorResponse(System.Net.HttpStatusCode.InternalServerError, "error");
}
return response;
}
Constants
//uniapp 外部系统联登 https://doc.dcloud.net.cn/uniCloud/uni-id/cloud-object.html#external
public static readonly string PushUrl = "you url";
//uniapp 注册
public static readonly string PushRegister = PushUrl + "externalRegister";
//uniapp 登录
public static readonly string PushLogin = PushUrl + "externalLogin";
//uniapp 修改信息
public static readonly string PushUpdateUser = PushUrl + "updateUserInfoByExternal ";
UniClient
public class UniClient
{
public string clientInfo { get; set; }
public string uniIdToken { get; set; }
}
Utils
/// <summary>
/// 根据用户信息 获取uniapp的uid, 这个就根据自己的业务来处理
/// </summary>
/// <param name="ui"></param>
/// <returns></returns>
public static string GetExternalUid(UserInfo ui)
{
//分别为角色ID、 用户ID和用户账号
return ui.Role + "_" + ui.Id + "_" + ui.userName;
}
//获取随机字符串 这里其实可以固定返回一组字符串
public static string GetNonce()
{
return GenerateRandomStringLinq(8);
}
private static string GenerateRandomStringLinq(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
Random random = new Random();
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
/// <summary>
/// uniapp 鉴权签名算法
/// </summary>
/// <param name="parameters"></param>
/// <param name="nonce"></param>
/// <param name="timestamp"></param>
/// <returns></returns>
public static string GetSignature(Dictionary<string, string> parameters, string nonce, long timestamp)
{
string paramsStr = GetParamsString(parameters);
using (HMACSHA256 hmacSha256 = new HMACSHA256(Encoding.UTF8.GetBytes(Constants.RequestAuthSecret + nonce)))
{
string message = timestamp.ToString() + paramsStr;
byte[] messageBytes = Encoding.UTF8.GetBytes(message);
byte[] hashBytes = hmacSha256.ComputeHash(messageBytes);
return ByteArrayToHexString(hashBytes).ToUpper();
}
}
/// <summary>
/// 获取当前时间戳 单位毫秒
/// </summary>
/// <returns></returns>
public static long GetNowTimeStamp()
{
return (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
}
private static string GetParamsString(Dictionary<string, string> parameters)
{
var keys = new List<string>(parameters.Keys);
keys.Sort();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < keys.Count; i++)
{
if (i != 0)
{
sb.Append("&");
}
sb.Append(keys[i]).Append("=").Append(parameters[keys[i]]);
}
return sb.ToString();
}
private static string ByteArrayToHexString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes)
{
string hex = b.ToString("x2");
sb.Append(hex);
}
return sb.ToString();
}
HttpHelper
/// <summary>
/// POST异步请求
///
/// </summary>
/// <param name="url">请求url</param>
/// <param name="jsonContent"></param>
/// <param name="headers"></param>
/// <returns></returns>
// 发送POST请求的函数
public static async Task<JObject> SendPostAsync(string url, string jsonContent, Dictionary<string, string> headers = null)
{
using (var client = new HttpClient())
{
var jsonObject = new JObject();
if (headers != null)
{
foreach (KeyValuePair<string, string> header in headers)
{
client.DefaultRequestHeaders.Add(header.Key, header.Value);
}
}
try
{
// 创建一个HttpContent对象,用于发送JSON数据
var httpContent = new StringContent(jsonContent, Encoding.UTF8, "application/json");
// 发送POST请求
HttpResponseMessage response = await client.PostAsync(url, httpContent);
// 确保HTTP请求成功
//response.EnsureSuccessStatusCode();
// 读取响应内容
var responseBody = await response.Content.ReadAsStringAsync();
//LoggerHelper.Info("请求:" + url + ",参数:" + jsonContent + ",结果:" + responseBody);
jsonObject = JsonConvert.DeserializeObject<JObject>(responseBody);
}
catch (HttpRequestException e)
{
LoggerHelper.Error("请求失败!",e);
}
return jsonObject;
}
}
tips: 出现了 "clientInfo.uniPlatform" is required. 是没有传参数clientInfo
参考 官方文档
APP端
this.$http
.post(`/uniCloudRegister`, {
clientInfo:JSON.stringify(uni.getSystemInfoSync())
})
.then(res =>{
uni.stopPullDownRefresh()
uni.hideNavigationBarLoading()
console.info(res)
}).catch(err => {
console.error(err)
uni.stopPullDownRefresh()
uni.hideNavigationBarLoading()
})
后台接口 UserController:ApiController
ConstantsConstants//业务系统登录后才需要联登到 uniCloud,所以不需要在注册时执行,而是单独给出了注册功能的接口
[HttpPost]
[Route("uniCloudRegister")]
public async Task<HttpResponseMessage> uniCloudRegister([FromBody] UniClient client)
{
HttpResponseMessage response = null;
try
{
//此为验证当前系统token并转为 user类的工具,这里就不给出详细示例了
var ui = JwtHelper.AnalysisToken(HttpContext.Current.Request);
//见 Utils
string uniAppUserName = Utils.GetExternalUid(ui);
string nonce = Utils.GetNonce();
// 获取当前时间戳(精确到毫秒)
long timestamp = Utils.GetNowTimeStamp();
Dictionary<string, string> paramsDictionary = new Dictionary<string, string>
{
{ "externalUid", uniAppUserName},
{ "nickname", ui.Name},
};
//签名算法见 Utils
string signature = Utils.GetSignature(paramsDictionary, nonce, timestamp);
//client.clientInfo 为JSON.stringify(uni.getSystemInfoSync()) 这里再转回json对象
var cliInfo = JsonConvert.DeserializeObject<JObject>(client.clientInfo);
Dictionary<string, object> param = new Dictionary<string, object>();
param.Add("clientInfo", cliInfo);
param.Add("uniIdToken", "");
param.Add("params", paramsDictionary);
// 将对象序列化为JSON字符串
string jsonContent = JsonConvert.SerializeObject(param);
Dictionary<string, string> headers = new Dictionary<string, string>()
{
{"uni-id-nonce",nonce },
{"uni-id-timestamp",timestamp + ""},
{"uni-id-signature",signature}
};
var res = await HttpHelper.SendPostAsync(Constants.PushRegister, jsonContent, headers);
if (res.Count > 0)
{
response = Request.CreateResponse(System.Net.HttpStatusCode.OK, res);
}
else
{
response = Request.CreateResponse(System.Net.HttpStatusCode.BadRequest, "error");
}
}
catch (Exception ex)
{
response = Request.CreateErrorResponse(System.Net.HttpStatusCode.InternalServerError, "error");
}
return response;
}
Constants
//uniapp 外部系统联登 https://doc.dcloud.net.cn/uniCloud/uni-id/cloud-object.html#external
public static readonly string PushUrl = "you url";
//uniapp 注册
public static readonly string PushRegister = PushUrl + "externalRegister";
//uniapp 登录
public static readonly string PushLogin = PushUrl + "externalLogin";
//uniapp 修改信息
public static readonly string PushUpdateUser = PushUrl + "updateUserInfoByExternal ";
UniClient
public class UniClient
{
public string clientInfo { get; set; }
public string uniIdToken { get; set; }
}
Utils
/// <summary>
/// 根据用户信息 获取uniapp的uid, 这个就根据自己的业务来处理
/// </summary>
/// <param name="ui"></param>
/// <returns></returns>
public static string GetExternalUid(UserInfo ui)
{
//分别为角色ID、 用户ID和用户账号
return ui.Role + "_" + ui.Id + "_" + ui.userName;
}
//获取随机字符串 这里其实可以固定返回一组字符串
public static string GetNonce()
{
return GenerateRandomStringLinq(8);
}
private static string GenerateRandomStringLinq(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
Random random = new Random();
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
/// <summary>
/// uniapp 鉴权签名算法
/// </summary>
/// <param name="parameters"></param>
/// <param name="nonce"></param>
/// <param name="timestamp"></param>
/// <returns></returns>
public static string GetSignature(Dictionary<string, string> parameters, string nonce, long timestamp)
{
string paramsStr = GetParamsString(parameters);
using (HMACSHA256 hmacSha256 = new HMACSHA256(Encoding.UTF8.GetBytes(Constants.RequestAuthSecret + nonce)))
{
string message = timestamp.ToString() + paramsStr;
byte[] messageBytes = Encoding.UTF8.GetBytes(message);
byte[] hashBytes = hmacSha256.ComputeHash(messageBytes);
return ByteArrayToHexString(hashBytes).ToUpper();
}
}
/// <summary>
/// 获取当前时间戳 单位毫秒
/// </summary>
/// <returns></returns>
public static long GetNowTimeStamp()
{
return (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
}
private static string GetParamsString(Dictionary<string, string> parameters)
{
var keys = new List<string>(parameters.Keys);
keys.Sort();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < keys.Count; i++)
{
if (i != 0)
{
sb.Append("&");
}
sb.Append(keys[i]).Append("=").Append(parameters[keys[i]]);
}
return sb.ToString();
}
private static string ByteArrayToHexString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes)
{
string hex = b.ToString("x2");
sb.Append(hex);
}
return sb.ToString();
}
HttpHelper
/// <summary>
/// POST异步请求
///
/// </summary>
/// <param name="url">请求url</param>
/// <param name="jsonContent"></param>
/// <param name="headers"></param>
/// <returns></returns>
// 发送POST请求的函数
public static async Task<JObject> SendPostAsync(string url, string jsonContent, Dictionary<string, string> headers = null)
{
using (var client = new HttpClient())
{
var jsonObject = new JObject();
if (headers != null)
{
foreach (KeyValuePair<string, string> header in headers)
{
client.DefaultRequestHeaders.Add(header.Key, header.Value);
}
}
try
{
// 创建一个HttpContent对象,用于发送JSON数据
var httpContent = new StringContent(jsonContent, Encoding.UTF8, "application/json");
// 发送POST请求
HttpResponseMessage response = await client.PostAsync(url, httpContent);
// 确保HTTP请求成功
//response.EnsureSuccessStatusCode();
// 读取响应内容
var responseBody = await response.Content.ReadAsStringAsync();
//LoggerHelper.Info("请求:" + url + ",参数:" + jsonContent + ",结果:" + responseBody);
jsonObject = JsonConvert.DeserializeObject<JObject>(responseBody);
}
catch (HttpRequestException e)
{
LoggerHelper.Error("请求失败!",e);
}
return jsonObject;
}
}
tips: 出现了 "clientInfo.uniPlatform" is required. 是没有传参数clientInfo
参考 官方文档
收起阅读 »
低版本 vue 无法安装 pinia 的解决方案
1 使用 pnpm 安装,安装时需锁定 pinia 版本
2 使用 yarn 安装,安装时需锁定 pinia 版本
1 使用 pnpm 安装,安装时需锁定 pinia 版本
2 使用 yarn 安装,安装时需锁定 pinia 版本

关于@uni-helper/uni-app-types 安装失败的原因
通过报错,可以得出是 ts 版本冲突;(大家检查一下 ts 版本;命令 tsc -v)所以需要到 npm 上安装低版本的,个人推荐 0.5.13,
地址:https://www.npmjs.com/package/@uni-helper/uni-app-types/v/0.5.13?activeTab=versions
通过报错,可以得出是 ts 版本冲突;(大家检查一下 ts 版本;命令 tsc -v)所以需要到 npm 上安装低版本的,个人推荐 0.5.13,
地址:https://www.npmjs.com/package/@uni-helper/uni-app-types/v/0.5.13?activeTab=versions

【奇异事件】云打包一直编译中
PC开发环境操作系统: MacPC/WinPC
开发环境操作系统版本号: 13.3.1 (22E261)/Win11
基项目创建方式: CLI
CLI版本号: 3.0.0-4000820240401001(应该没关系)
问题出现:
使用调试基座开发没有任何问题,直到发版需要打包;
无论如何使用HbuilderX进行打包就会出现,一直在编译,后台esbuild一直在运行;
代码一直没有提交进入云端打包,改依赖换CLI版本甚至换HbuilderX版本都无法解决;
问题排查
一次次的回退git,才定位到问题
没错,就是watch这个配置项导致一直编译无法完成
这个watch是为什么要加呢,因为我使用了unocss。
他在Windows下运行经常会出现错误导致app需要重新运行,如图
所以我在 官方issues 找到了一个相对简单的解决方法
没想到会出现一个更加诡异的问题
希望能帮到你们
PC开发环境操作系统: MacPC/WinPC
开发环境操作系统版本号: 13.3.1 (22E261)/Win11
基项目创建方式: CLI
CLI版本号: 3.0.0-4000820240401001(应该没关系)
问题出现:
使用调试基座开发没有任何问题,直到发版需要打包;
无论如何使用HbuilderX进行打包就会出现,一直在编译,后台esbuild一直在运行;
代码一直没有提交进入云端打包,改依赖换CLI版本甚至换HbuilderX版本都无法解决;
问题排查
一次次的回退git,才定位到问题
没错,就是watch这个配置项导致一直编译无法完成
这个watch是为什么要加呢,因为我使用了unocss。
他在Windows下运行经常会出现错误导致app需要重新运行,如图
所以我在 官方issues 找到了一个相对简单的解决方法
没想到会出现一个更加诡异的问题
希望能帮到你们
收起阅读 »
鸿蒙 1.3.5 无法登录腾讯云 IM,或其他 Websocket 问题
修改 entry/src/main/ets/uni-app-harmony/uni.api.ets ws.connect 方法入参 protocol 的值为 args.protocols ? Array.isArray(args.protocols) ? args.protocols.join(',') : args.protocols : ''
修改 entry/src/main/ets/uni-app-harmony/uni.api.ets ws.connect 方法入参 protocol 的值为 args.protocols ? Array.isArray(args.protocols) ? args.protocols.join(',') : args.protocols : ''
收起阅读 »