Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] 统一服务消息 uniformMessage.send 增加 #6

Closed
gicexxopode opened this issue Aug 31, 2021 · 7 comments
Closed

[FEATURE] 统一服务消息 uniformMessage.send 增加 #6

gicexxopode opened this issue Aug 31, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@gicexxopode
Copy link

gicexxopode commented Aug 31, 2021

统一服务消息uniformMessage.send 这个挺常用的,还没有API

@gicexxopode gicexxopode added the enhancement New feature or request label Aug 31, 2021
@fudiwei
Copy link
Owner

fudiwei commented Aug 31, 2021

你是指 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/uniform-message/uniformMessage.send.html 这个接口吗?

我看它的用途是用一个接口统一公众号和小程序的模版消息,可小程序的模版消息业务不是已经下线了么?如果你只发公众号模版消息的话,用它单独的接口不可以吗?还是这个接口有我没注意到的什么其他特殊的呢?

@fudiwei fudiwei changed the title 统一服务消息uniformMessage.send [FEATURE] 统一服务消息增加 [FEATURE] 统一服务消息 uniformMessage.send 增加 Aug 31, 2021
@gicexxopode
Copy link
Author

gicexxopode commented Sep 1, 2021

你是指 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/uniform-message/uniformMessage.send.html 这个接口吗?

我看它的用途是用一个接口统一公众号和小程序的模版消息,可小程序的模版消息业务不是已经下线了么?如果你只发公众号模版消息的话,用它单独的接口不可以吗?还是这个接口有我没注意到的什么其他特殊的呢?

你说的也有道理,确实可以使用公众号模板进行发送,这其实就像什么呢 Nullable 或 int? 还有它们值的判空如 public int? Id
if(Id!=null) or if(Id.HasValue) 判断其实是一样的,提供了二种入口。再说直白点就是,我可以不用,但是你不能没有,:smile::smile:

@fudiwei
Copy link
Owner

fudiwei commented Sep 1, 2021

啊这... 🤦‍♂️

如果你确实需要这个接口,可以参考文档《如何扩展额外的 API?》一节自行扩展;或者你也可以发个 PR 过来。

但暂时不会发布一个新版本出来,毕竟这是一个可有可无的 API,为此发一版本没啥必要你说是吧?可以考虑当有其他新的 API 加入后再一同发布。

P.S. 其实 Nullable 的结构体不建议用 == null!= null 来判空,因为有运算符重载这种东西存在可能会导致误判,微软提供了 HasValue 属性也正是因为此。

@gicexxopode
Copy link
Author

我已经在我项目中扩展了,就是使用时搜索没找到这个API,所以提了这个功能,这个你可以按你的想法来,必竞每个人的标准都不一样。
P.S其实 Nullable 的结构体不建议用 == null、!= null 来判空,这个我不太赞同你的观点参见
https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/builtin-types/nullable-value-types
这必竟是官方出品的文档,相对来说要比民间要权威一些
另外官方推荐了新写法
int? a = 42;
if (a is int valueOfA)
{
Console.WriteLine($"a is {valueOfA}");
}
else
{
Console.WriteLine("a does not have a value");
}

@fudiwei
Copy link
Owner

fudiwei commented Sep 2, 2021

因为 System.Int32 并没有重载运算符…… 当你在上下文已知的是个 int? 的情况下,确实可以这么判空。

但如果你是个泛型方法呢?你在这个方法里并不知道外面传进来的是个 int? 还是某个你自定义的、鬼知道重没重载过运算符的 Struct 呢?

P.S. 其实对于 Primitive Types 而言,C# 的编译器是做了优化的,你会在读 IL 层代码时发现,a != null 会被翻译成和 a.HasValue 一样的;而如果是个引用类型,a != null 就是 a != null,没啥可优化的。从 IL 结果上你也能看出,到底谁是更被推荐的。

int? i = 0;

if (i != null) {
    i++;
}

if (i.HasValue) {
    i++;
}

// 以上的判空部分均被翻译为:
// call System.Boolean System.Nullable`1<System.Int32>::get_HasValue()
// 完整 IL 代码请见下图

image

普通的引用类型判空的 IL 代码就不贴了,感兴趣的话你可以自己尝试一下,对比看看有何不同。

@fudiwei
Copy link
Owner

fudiwei commented Sep 3, 2021

Support this on release v1.7.0.

请注意新增的接口模型中不包含微信已标记为废弃的 weapp_template_msg 相关字段,只包含 mp_template_msg 相关字段。

感谢建议,下次欢迎直接 PR,开源项目需要社区的共同参与 🙏

@fudiwei fudiwei closed this as completed Sep 3, 2021
@gicexxopode
Copy link
Author

受教受教,谢谢。没想到反映这么迅速,要不我就直接提交PR了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants