没有不值得去解决的问题,也没有不值得去学习的技术!

International Phone Number Support in Yii2.0.9 with Ronglianyun and Yunpian

编辑\common\config\main.php,定义别名

1. Refer to the previous URL: https://www.shuijingwanwq.com/2016/07/09/1129/;

2. The implementation for obtaining the mobile registration verification code needs to be compatible with previous client versions that only supported mainland China. Therefore, the country area code ID is allowed to be empty, with a default value of 0, as shown in Figure 1:

The implementation for obtaining the mobile registration verification code needs to be compatible with previous client versions that only supported mainland China. Therefore, the country area code ID is allowed to be empty, with a default value of 0
Figure 1

3. The validation rule where the country area code ID is allowed to be empty and defaults to 0 is shown in Figure 2:

The validation rule where the country area code ID is allowed to be empty and defaults to 0
Figure 2

4. The verification code is kept in the cache for 1800 seconds. Its variable name is the concatenation of the country area code ID and the mobile number to ensure uniqueness, as shown in Figure 3:

The verification code is kept in the cache for 1800 seconds. Its variable name is the concatenation of the country area code ID and the mobile number to ensure uniqueness
Figure 3

5. The processing logic for sending template SMS is basically the same as in the previous URL. If the sending is successful, it calculates the number of sends for today and stores it in the cache to limit the daily sending frequency, as shown in Figure 4:

The processing logic for sending template SMS is basically the same as in the previous URL. If the sending is successful, it calculates the number of sends for today and stores it in the cache to limit the daily sending frequency
Figure 4

6. Validation for the number of template SMS sent within a day, limiting the daily quantity to 5 messages, as shown in Figures 5 and 6:

Validation for the number of template SMS sent within a day, limiting the daily quantity to 5 messages
Figure 5
Validation for the number of template SMS sent within a day, limiting the daily quantity to 5 messages
Figure 6

7. To support sending SMS via Yunpian, copy Yunpian from the previous URL to \vendor\yunpian, as shown in Figure 7:

To support sending SMS via Yunpian, copy Yunpian from the previous URL to \vendor\yunpian
Figure 7

8. Edit \common\config\main.php to define an alias, as shown in Figure 8:
‘aliases’ => [
‘@yunpian’ => ‘@vendor/yunpian’,
],

Edit \common\config\main.php to define an alias
Figure 8

9. Edit \common\config\params.php for the Yunpian SMS interface configuration, as shown in Figure 9:

Edit \common\config\params.php for the Yunpian SMS interface configuration
Figure 9

10. Search for $GLOBALS[‘setting_config’][‘yunpian’] in \vendor\yunpian and replace it with: Yii::$app->params[‘yunpian’], as shown in Figure 10:

Search for $GLOBALS['setting_config']['yunpian'] in \vendor\yunpian and replace it with: Yii::$app->params['yunpian']
Figure 10

11. To support sending SMS via Yunpian, copy sms.php from the previous URL to \common\components\Sms.php. This allows the corresponding Yunpian class libraries to be referenced within it, as shown in Figure 11:

To support sending SMS via Yunpian, copy sms.php from the previous URL to \common\components\Sms.php. This allows the corresponding Yunpian class libraries to be referenced within it
Figure 11

12. The international SMS sending test is successful, as shown in Figure 12:

The international SMS sending test is successful
Figure 12

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系