NIUSHOP 采用ThinkPHP5.0 + MySQL 开发语言,面向对象的技术架构设计开发。完全开源,二次开发非常方便,小编对他还是比较了解的,今天小编为大家讲解企业2.4版本的短信接口替换,使用的接口是我们短信宝群发平台的短信接口,我们短信宝群发短信平台非常稳定,发送速度快,注册还送测试短信,推荐大家使用。
首先我们修改项目\template\adminblue\Config\messageConfig.html文件的137~187行左右,修改代码为:
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
|
< div class = "set-style" > < dl > < dt >是否开启:</ dt > < dd > < input id = "sms_is_use" type = "checkbox" class = "checkbox" {if condition = "$mobile_message.is_use=='1'" } checked = "checked" {/if}/> < p class = "hint" style = "margin-top:10px;" >当前使用短信宝短信配置</ p > </ dd > </ dl > < dl > < dt >短信签名:</ dt > < dd > < input id = "free_sign_name" type = "text" value = "{$mobile_message['value']['freeSignName']}" class = "input-common long" /> </ dd > </ dl > < dl > < dt >短信宝账号:</ dt > < dd > < input id = "app_key" type = "text" value = "{$mobile_message['value']['appKey']}" class = "input-common long" /> </ dd > </ dl > < dl > < dt >短信宝密码:</ dt > < dd > < input id = "secret_key" type = "text" value = "{$mobile_message['value']['secretKey']}" class = "input-common long" /> </ dd > </ dl > < dl > < dt ></ dt > < dd > < button class = "btn-common btn-big" onclick = "setConfigAjax();" >保存</ button > < button class = "btn-common-cancle btn-big" onclick = "javascript:history.back(-1);" >返回</ button > </ dd > </ dl > </ div > |
接着我们找到短信模板页面,\template\adminblue\Config\notifySmsTemplate.html;替换54~69行左右的代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
< div class = "right_main" > < div class = "main-top" >您正在编辑< a href = "javascript:;" id = "update_nameid" ></ a >通知模板</ div > < div class = "qianming" >< div style = "width:75px;float:left;" >模板:</ div >< input type = "text" id = "template_titleid" value = "{$template_select.template_title}" style = "margin-right: 15px !important;" class = "input-common" /> </ div > < div class = "qianming" > </ div > < div class = "bl" > < div style = "width:75px;float:left;" >可用变量:</ div > < div style = "width:88%;float: left;font-size:13px;" id = "user_variable" > {foreach name="template_item_list" item="item_obj"} {$item_obj.replace_name}({$item_obj.item_name}), {/foreach} </ div > </ div > </ div > </ div > |
接着我们打开\data\service\Member.php文件,替换registerMember方法,代码为:
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
|
public function registerMember( $user_name , $password , $email , $mobile , $user_qq_id , $qq_info , $wx_openid , $wx_info , $wx_unionid ) { // if (! empty($user_name)) { // if (! preg_match("/^(?!\d+$)[\da-zA-Z]*$/i", $user_name)) { // return USER_WORDS_ERROR; // } // } if (! empty ( $user_qq_id ) || ! empty ( $wx_openid ) || ! empty ( $wx_unionid )) { $is_false = true; } else { if (trim( $user_name ) != "" ) { $error_info = $this ->verifyValue( $user_name , $password , "plain" ); $is_false = $error_info [0]; } else { if ( $mobile != "" && $email == "" ) { if ( $user_name == "" ) { $user_name = $mobile ; $error_info = $this ->verifyValue( $user_name , $password , "mobile" ); $is_false = $error_info [0]; } } else { $error_info = $this ->verifyValue( $user_name , $password , "email" ); $is_false = $error_info [0]; } } } if (! $is_false ) { return $error_info [1]; } $res = parent::add( $user_name , $password , $email , $mobile , 0, $user_qq_id , $qq_info , $wx_openid , $wx_info , $wx_unionid , 1); if ( $res > 0) { // 获取默认会员等级id $member_level = new NsMemberLevelModel(); $level_info = $member_level ->getInfo([ 'is_default' => 1 ], 'level_id' ); $member_level = $level_info [ 'level_id' ]; $member = new NsMemberModel(); $user_info_obj = parent::getUserInfoByUid( $res ); $data = array ( 'uid' => $res , 'member_name' => $user_info_obj [ "nick_name" ], 'member_level' => $member_level , 'reg_time' => time() ); $retval = $member ->save( $data ); if ( $mobile ) { $params [ 'shop_id' ] = 0; $params [ 'user_id' ] = $res ; $result = runhook( 'Notify' , 'registAfter' , $params ); } hook( 'memberRegisterSuccess' , $data ); // 注册会员送积分 $promote_reward_rule = new PromoteRewardRule(); // 添加关注 switch (NS_VERSION) { case NS_VER_B2C: break ; case NS_VER_B2C_FX: if (! empty ( $_SESSION [ 'source_uid' ])) { // 判断当前版本 $nfx_user = new NfxUser(); $nfx_user ->userAssociateShop( $res , 0, $_SESSION [ 'source_uid' ]); } else { // 判断当前版本 $nfx_user = new NfxUser(); $nfx_user ->userAssociateShop( $res , 0, 0); } break ; } // 平台赠送积分 $promote_reward_rule ->RegisterMemberSendPoint(0, $res ); // 注册成功后短信与邮箱提醒 $params [ 'shop_id' ] = $this ->instance_id; $params [ 'user_id' ] = $res ; runhook( 'Notify' , 'registAfter' , $params ); // 直接登录 if (! empty ( $user_name )) { $this ->login( $user_name , $password ); } elseif (! empty ( $mobile )) { $this ->login( $mobile , $password ); } elseif (! empty ( $email )) { $this ->login( $email , $password ); } elseif (! empty ( $user_qq_id )) { $this ->qqLogin( $user_qq_id ); } elseif (! empty ( $wx_openid )) { $this ->wchatLogin( $wx_openid ); } elseif (! empty ( $wx_unionid )) { $this ->wchatUnionLogin( $wx_unionid ); } } return $res ; // TODO Auto-generated method stub } |
接着我们打开项目\data\extend\hook\Notify.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
|
<?php namespace data\extend\hook; use data\model\WebSiteModel; use data\model\UserModel; use data\model\ConfigModel; use data\model\NoticeTemplateModel; use data\model\NsOrderGoodsModel; use data\model\NsOrderModel; use phpDocumentor\Reflection\Types\This; use data\model\NsOrderGoodsExpressModel; use think\Log; use data\model\NsOrderPaymentModel; use data\service\Notice; class Notify { public $result = array ( "code" =>0, "message" => "success" , "param" => "" ); /** * 邮件的配置信息 * @var unknown */ public $email_is_open =0; public $email_host = "" ; public $email_port = "" ; public $email_addr = "" ; public $email_id = "" ; public $email_pass = "" ; public $email_is_security =false; /** * 短信的配置信息 * @var unknown */ public $mobile_is_open ; public $appKey = "" ; public $secretKey = "" ; public $freeSignName = "" ; public $shop_name ; public $ali_use_type =0; /** * 得到系统通知的配置信息 * @param unknown $shop_id */ private function getShopNotifyInfo( $shop_id ){ $website_model = new WebSiteModel(); $website_obj = $website_model ->getInfo( "1=1" , "title" ); if ( empty ( $website_obj )){ $this ->shop_name= "NiuShop开源商城" ; } else { $this ->shop_name= $website_obj [ "title" ]; } $config_model = new ConfigModel(); #查看邮箱是否开启 $email_info = $config_model ->getInfo([ "instance_id" => $shop_id , "`key`" => "EMAILMESSAGE" ], "*" ); if (! empty ( $email_info )){ $this ->email_is_open= $email_info [ "is_use" ]; $value = $email_info [ "value" ]; if (! empty ( $value )){ $email_array =json_decode( $value , true); $this ->email_host= $email_array [ "email_host" ]; $this ->email_port= $email_array [ "email_port" ]; $this ->email_addr= $email_array [ "email_addr" ]; $this ->email_id= $email_array [ "email_id" ]; $this ->email_pass= $email_array [ "email_pass" ]; $this ->email_is_security= $email_array [ "email_is_security" ]; } } $mobile_info = $config_model ->getInfo([ "instance_id" => $shop_id , "`key`" => "MOBILEMESSAGE" ], "*" ); if (! empty ( $mobile_info )){ $this ->mobile_is_open= $mobile_info [ "is_use" ]; $value = $mobile_info [ "value" ]; if (! empty ( $value )){ $mobile_array =json_decode( $value , true); $this ->appKey= $mobile_array [ "appKey" ]; $this ->secretKey= $mobile_array [ "secretKey" ]; $this ->freeSignName= $mobile_array [ "freeSignName" ]; $this ->ali_use_type= $mobile_array [ "user_type" ]; if ( empty ( $this ->ali_use_type)){ $this ->ali_use_type=0; } } } } public function sendSMS( $appkey , $secret , $signName , $smsParam , $send_mobile , $template_code ) { $smsParam =json_decode( $smsParam ,true); $content = strtr ( $template_code , $smsParam ); //替换模板中的变量 $contents = '【' . $signName . '】' . $content ; $url = 'http://api.smsbao.com/sms?u=' . $appkey . '&p=' .md5( $secret ). '&m=' . $send_mobile . '&c=' . $contents ; $result = file_get_contents ( $url ); return $result ; } /** * 查询模板的信息 * @param unknown $shop_id * @param unknown $template_code * @param unknown $type * @return unknown */ private function getTemplateDetail( $shop_id , $template_code , $type , $notify_type = "user" ){ $template_model = new NoticeTemplateModel(); $template_obj = $template_model ->getInfo([ "instance_id" => $shop_id , "template_type" => $type , "template_code" => $template_code , "notify_type" => $notify_type ]); return $template_obj ; } /** * 处理阿里大于 的返回数据 * @param unknown $result */ private function dealAliSmsResult( $result ){ $deal_result = array (); try { if ( $this ->ali_use_type==0){ #旧用户发送 if (! empty ( $result )){ if (!isset( $result ->result)){ $result =json_decode(json_encode( $result ), true); #发送失败 $deal_result [ "code" ]= $result [ "code" ]; $deal_result [ "message" ]= $result [ "sub_msg" ]; } else { #发送成功 $deal_result [ "code" ]=0; $deal_result [ "message" ]= "发送成功" ; } } } else { #新用户发送 if (! empty ( $result )){ if ( $result ->Code== "OK" ){ #发送成功 $deal_result [ "code" ]=0; $deal_result [ "message" ]= "发送成功" ; } else { #发送失败 $deal_result [ "code" ]=-1; $deal_result [ "message" ]= $result ->Message; } } } } catch (\Exception $e ) { $deal_result [ "code" ]=-1; $deal_result [ "message" ]= "发送失败!" ; } return $deal_result ; } /** * 用户注册成功后 * @param string $params */ public function registAfter( $params =null){ /** * 店铺id */ $shop_id = $params [ "shop_id" ]; #查询系统配置信息 $this ->getShopNotifyInfo(0); /** * 用户id */ $user_id = $params [ "user_id" ]; $user_model = new UserModel(); $user_obj = $user_model ->get( $user_id ); $mobile = "" ; $user_name = "" ; $email = "" ; if ( empty ( $user_obj )){ $user_name = "用户" ; } else { $user_name = $user_obj [ "nick_name" ]; $mobile = $user_obj [ "user_tel" ]; $email = $user_obj [ "user_email" ]; } #短信验证 if (! empty ( $mobile ) && $this ->mobile_is_open==1){ $template_obj = $this ->getTemplateDetail( $shop_id , "after_register" , "sms" ); if (! empty ( $template_obj ) && $template_obj [ "is_enable" ]==1){ $sms_params = array ( "shop_name" => $this ->shop_name, "shopname" => $this ->shop_name, "user_name" => $user_name , "username" => $user_name ); $result = $this ->sendSMS( $this ->appKey, $this ->secretKey, $this ->freeSignName, json_encode( $sms_params ), $mobile , $template_obj [ "template_title" ], $this ->ali_use_type); if ( $result == '0' ) { $this ->result[ "code" ]=0; $this ->result[ "message" ]= "发送成功!" ; } else { $this ->result[ "code" ]= $result ; $this ->result[ "message" ]= "发送失败!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "商家没开启短信模板!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "商家没开启短信模板!" ; } #邮箱验证 if (! empty ( $email ) && $this ->email_is_open==1){ $template_obj = $this ->getTemplateDetail( $shop_id , "after_register" , "email" ); if (! empty ( $template_obj ) && $template_obj [ "is_enable" ]==1){ $content = $template_obj [ "template_content" ]; $content = str_replace ( "{商场名称}" , $this ->shop_name, $content ); $content = str_replace ( "{用户名称}" , $user_name , $content ); $send_title = $template_obj [ "template_title" ]; $send_title = str_replace ( "{商场名称}" , $this ->shop_name, $send_title ); $send_title = str_replace ( "{用户名称}" , $user_name , $send_title ); $result =emailSend( $this ->email_host, $this ->email_id, $this ->email_pass, $this ->email_port, $this ->email_is_security, $this ->email_addr, $email , $send_title , $content , $this ->shop_name); if ( $result ){ $this ->result[ "code" ]=0; $this ->result[ "message" ]= "发送成功!" ; } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "发送失败!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "商家没开启邮箱验证" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "商家没开启邮箱验证" ; } return $this ->result; } /** * 注册短信验证 * @param string $params */ public function registBefor( $params =null){ $rand = rand(100000,999999); $mobile = $params [ "mobile" ]; $shop_id = $params [ "shop_id" ]; #查询系统配置信息 $this ->getShopNotifyInfo( $shop_id ); $result = "" ; if (! empty ( $mobile ) && $this ->mobile_is_open==1){ $template_obj = $this ->getTemplateDetail( $shop_id , "register_validate" , "sms" ); if (! empty ( $template_obj ) && $template_obj [ "is_enable" ]==1){ $sms_params = array ( "number" => $rand . "" ); $this ->result[ "param" ]= $rand ; if (! empty ( $this ->appKey) && ! empty ( $this ->secretKey) && ! empty ( $this ->freeSignName) && ! empty ( $template_obj [ "template_title" ])){ $result = $this ->sendSMS( $this ->appKey, $this ->secretKey, $this ->freeSignName, json_encode( $sms_params ), $mobile , $template_obj [ "template_title" ], $this ->ali_use_type); if ( $result == '0' ) { $this ->result[ "code" ]=0; $this ->result[ "message" ]= "发送成功!" ; $this ->result[ "param" ]= $rand ; } else { $this ->result[ "code" ]= $result ; $this ->result[ "message" ]= "发送失败!" ; $this ->result[ "param" ]= $rand ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "短信配置信息有误!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "短信通知模板有误!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "店家没有开启短信验证" ; } return $this ->result; } /** * 注册邮箱验证 * 已测试 * @param string $params */ public function registEmailValidation( $params =null){ $rand = rand(100000,999999); $email = $params [ "email" ]; $shop_id = $params [ "shop_id" ]; #查询系统配置信息 $this ->getShopNotifyInfo( $shop_id ); if (! empty ( $email ) && $this ->email_is_open==1){ $template_obj = $this ->getTemplateDetail( $shop_id , "register_validate" , "email" ); if (! empty ( $template_obj ) && $template_obj [ "is_enable" ]==1){ $content = $template_obj [ "template_content" ]; $content = str_replace ( "{验证码}" , $rand , $content ); if (! empty ( $this ->email_host) && ! empty ( $this ->email_id) && ! empty ( $this ->email_pass) && ! empty ( $this ->email_addr)){ $result =emailSend( $this ->email_host, $this ->email_id, $this ->email_pass, $this ->email_port, $this ->email_is_security, $this ->email_addr, $email , $template_obj [ "template_title" ], $content , $this ->shop_name); $this ->result[ "param" ]= $rand ; if ( $result ){ $this ->result[ "code" ]=0; $this ->result[ "message" ]= "发送成功!" ; } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "发送失败!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "邮箱配置信息有误!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "配置邮箱注册验证模板有误!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "店家没有开启邮箱验证" ; } return $this ->result; } /** * 订单发货 * @param string $params */ public function orderDelivery( $params =null){ #查询系统配置信息 $this ->getShopNotifyInfo(0); $order_goods_ids = $params [ "order_goods_ids" ]; $order_goods_str = explode ( "," , $order_goods_ids ); $result = "" ; $user_name = "" ; $order_model = new NsOrderModel(); $user_model = new UserModel(); if ( count ( $order_goods_str )>0){ $order_goods_id = $order_goods_str [0]; $order_goods_model = new NsOrderGoodsModel(); $order_goods_obj = $order_goods_model ->get( $order_goods_id ); $shop_id = $order_goods_obj [ "shop_id" ]; $order_id = $order_goods_obj [ "order_id" ]; $order_obj = $order_model ->get( $order_id ); $buyer_id = $order_obj [ "buyer_id" ]; $user_obj = $user_model ->get( $buyer_id ); $user_name = $user_obj [ "nick_name" ]; $goods_name = $order_goods_obj [ "goods_name" ]; $goods_sku = $order_goods_obj [ "sku_name" ]; $order_no = $order_obj [ "out_trade_no" ]; $order_money = $order_obj [ "order_money" ]; $goods_money = $order_goods_obj [ "goods_money" ]; $mobile = $order_obj [ "receiver_mobile" ]; $goods_express_model = new NsOrderGoodsExpressModel(); $express_obj = $goods_express_model ->getInfo([ "order_id" => $order_id , "order_goods_id_array" => $order_goods_ids ], "*" ); $sms_params = array ( "shop_name" => $this ->shop_name, "user_name" => $user_name , "goods_name" => $goods_name , "goods_sku" => $goods_sku , "order_no" => $order_no , "order_money" => $order_money , "goods_money" => $goods_money , "express_company" => $express_obj [ "express_name" ], "express_no" => $express_obj [ "express_no" ], "shopname" => $this ->shop_name, "username" => $user_name , "goodsname" => $goods_name , "goodssku" => $goods_sku , "orderno" => $order_no , "ordermoney" => $order_money , "goodsmoney" => $goods_money , "expresscompany" => $express_obj [ "express_name" ], "expressno" => $express_obj [ "express_no" ] ); #短信发送 if (! empty ( $mobile ) && $this ->mobile_is_open==1){ $template_obj = $this ->getTemplateDetail( $shop_id , "order_deliver" , "sms" ); if (! empty ( $template_obj ) && $template_obj [ "is_enable" ]==1){ $this ->sendSMS( $template_obj , $shop_id , $buyer_id , $mobile , $sms_params , "订单发货短信发送" , 5); } } // 邮件发送 if (! empty ( $user_obj )) { $email = $user_obj [ "user_email" ]; if (! empty ( $email ) && $this ->email_is_open == 1) { $template_obj = $this ->getTemplateDetail( $shop_id , "order_deliver" , "email" ); if (! empty ( $template_obj ) && $template_obj [ "is_enable" ] == 1) { $content = $template_obj [ "template_content" ]; $content = str_replace ( "{商场名称}" , $this ->shop_name, $content ); $content = str_replace ( "{用户名称}" , $user_name , $content ); $content = str_replace ( "{商品名称}" , $goods_name , $content ); $content = str_replace ( "{商品规格}" , $goods_sku , $content ); $content = str_replace ( "{主订单号}" , $order_no , $content ); $content = str_replace ( "{订单金额}" , $order_money , $content ); $content = str_replace ( "{商品金额}" , $goods_money , $content ); $content = str_replace ( "{物流公司}" , $express_obj [ "express_name" ], $content ); $content = str_replace ( "{快递编号}" , $express_obj [ "express_no" ], $content ); $send_title = $template_obj [ "template_title" ]; $send_title = str_replace ( "{商场名称}" , $this ->shop_name, $send_title ); $send_title = str_replace ( "{用户名称}" , $user_name , $send_title ); $send_title = str_replace ( "{商品名称}" , $goods_name , $send_title ); $send_title = str_replace ( "{商品规格}" , $goods_sku , $send_title ); $send_title = str_replace ( "{主订单号}" , $order_no , $send_title ); $send_title = str_replace ( "{订单金额}" , $order_money , $send_title ); $send_title = str_replace ( "{商品金额}" , $goods_money , $send_title ); $send_title = str_replace ( "{物流公司}" , $express_obj [ "express_name" ], $send_title ); $send_title = str_replace ( "{快递编号}" , $express_obj [ "express_no" ], $send_title ); $this ->createNoticeEmailRecords( $shop_id , $buyer_id , $email , $send_title , $content , 5); } } } } } /** * 订单确认 * @param string $params */ public function orderComplete( $params =null){ #查询系统配置信息 $this ->getShopNotifyInfo(0); $order_id = $params [ "order_id" ]; $order_model = new NsOrderModel(); $order_obj = $order_model ->get( $order_id ); $shop_id = $order_obj [ "shop_id" ]; $buyer_id = $order_obj [ "buyer_id" ]; $user_name = $order_obj [ "receiver_name" ]; $order_no = $order_obj [ "out_trade_no" ]; $order_money = $order_obj [ "order_money" ]; $mobile = $order_obj [ "receiver_mobile" ]; $sms_params = array ( "shop_name" => $this ->shop_name, "user_name" => $user_name , "order_no" => $order_no , "order_money" => $order_money , "shopname" => $this ->shop_name, "username" => $user_name , "orderno" => $order_no , "ordermoney" => $order_money ); // 短信发送 if (! empty ( $mobile ) && $this ->mobile_is_open == 1) { $template_obj = $this ->getTemplateDetail( $shop_id , "confirm_order" , "sms" ); if (! empty ( $template_obj ) && $template_obj [ "is_enable" ] == 1) { $this ->sendSMS( $template_obj , $shop_id , $buyer_id , $mobile , $sms_params , "订单确认短信发送" , 2); } } // 邮件发送 $user_model = new UserModel(); $user_obj = $user_model ->get( $buyer_id ); if (! empty ( $user_obj )) { $email = $user_obj [ "user_email" ]; if (! empty ( $email ) && $this ->email_is_open == 1) { $template_obj = $this ->getTemplateDetail( $shop_id , "confirm_order" , "email" ); if (! empty ( $template_obj ) && $template_obj [ "is_enable" ] == 1) { $content = $template_obj [ "template_content" ]; $content = str_replace ( "{商场名称}" , $this ->shop_name, $content ); $content = str_replace ( "{用户名称}" , $user_name , $content ); $content = str_replace ( "{主订单号}" , $order_no , $content ); $content = str_replace ( "{订单金额}" , $order_money , $content ); $send_title = $template_obj [ "template_title" ]; $send_title = str_replace ( "{商场名称}" , $this ->shop_name, $send_title ); $send_title = str_replace ( "{用户名称}" , $user_name , $send_title ); $send_title = str_replace ( "{主订单号}" , $order_no , $send_title ); $send_title = str_replace ( "{订单金额}" , $order_money , $send_title ); $this ->createNoticeEmailRecords( $shop_id , $buyer_id , $email , $send_title , $content , 2); } } } } /** * 订单付款成功 * @param string $params */ public function orderPay( $params =null){ #查询系统配置信息 $this ->getShopNotifyInfo(0); $order_id = $params [ "order_id" ]; $order_model = new NsOrderModel(); $order_obj = $order_model ->get( $order_id ); $shop_id = $order_obj [ "shop_id" ]; $buyer_id = $order_obj [ "buyer_id" ]; $user_name = $order_obj [ "receiver_name" ]; $order_no = $order_obj [ "out_trade_no" ]; $order_money = $order_obj [ "order_money" ]; $mobile = $order_obj [ "receiver_mobile" ]; $goods_money = $order_obj [ "goods_money" ]; $sms_params = array ( "shop_name" => $this ->shop_name, "user_name" => $user_name , "order_no" => $order_no , "order_money" => $order_money , "goods_money" => $goods_money , "shopname" => $this ->shop_name, "username" => $user_name , "orderno" => $order_no , "ordermoney" => $order_money , "goodsmoney" => $goods_money ); #短信发送 if (! empty ( $mobile ) && $this ->mobile_is_open==1){ $template_obj = $this ->getTemplateDetail( $shop_id , "pay_success" , "sms" ); if (! empty ( $template_obj ) && $template_obj [ "is_enable" ]==1){ $this ->sendSMS( $template_obj , $shop_id , $buyer_id , $mobile , $sms_params , "订单付款成功通知" , 3); } } #邮件发送 $user_model = new UserModel(); $user_obj = $user_model ->get( $buyer_id ); if (! empty ( $user_obj )){ $email = $user_obj [ "user_email" ]; if (! empty ( $email ) && $this ->email_is_open==1){ $template_obj = $this ->getTemplateDetail( $shop_id , "pay_success" , "email" ); if (! empty ( $template_obj ) && $template_obj [ "is_enable" ]==1){ $content = $template_obj [ "template_content" ]; $content = str_replace ( "{商场名称}" , $this ->shop_name, $content ); $content = str_replace ( "{用户名称}" , $user_name , $content ); $content = str_replace ( "{主订单号}" , $order_no , $content ); $content = str_replace ( "{订单金额}" , $order_money , $content ); $content = str_replace ( "{商品金额}" , $goods_money , $content ); $send_title = $template_obj [ "template_title" ]; $send_title = str_replace ( "{商场名称}" , $this ->shop_name, $send_title ); $send_title = str_replace ( "{用户名称}" , $user_name , $send_title ); $send_title = str_replace ( "{主订单号}" , $order_no , $send_title ); $send_title = str_replace ( "{订单金额}" , $order_money , $send_title ); $send_title = str_replace ( "{商品金额}" , $goods_money , $send_title ); $this ->createNoticeEmailRecords( $shop_id , $buyer_id , $email , $send_title , $content , 3); } } } } /** * 订单创建成功 * @param string $params */ public function orderCreate( $params =null){ #查询系统配置信息 $this ->getShopNotifyInfo(0); $order_id = $params [ "order_id" ]; $order_model = new NsOrderModel(); $order_obj = $order_model ->get( $order_id ); $shop_id = $order_obj [ "shop_id" ]; $buyer_id = $order_obj [ "buyer_id" ]; $user_name = $order_obj [ "receiver_name" ]; $order_no = $order_obj [ "out_trade_no" ]; $order_money = $order_obj [ "order_money" ]; $mobile = $order_obj [ "receiver_mobile" ]; $goods_money = $order_obj [ "goods_money" ]; $sms_params = array ( "shop_name" => $this ->shop_name, "user_name" => $user_name , "order_no" => $order_no , "order_money" => $order_money , "goods_money" => $goods_money , "shopname" => $this ->shop_name, "username" => $user_name , "orderno" => $order_no , "ordermoney" => $order_money , "goodsmoney" => $goods_money ); #短信发送 if (! empty ( $mobile ) && $this ->mobile_is_open==1){ $template_obj = $this ->getTemplateDetail( $shop_id , "create_order" , "sms" ); if (! empty ( $template_obj ) && $template_obj [ "is_enable" ]==1){ $this ->sendSMS( $template_obj , $shop_id , $buyer_id , $mobile , $sms_params , "订单创建成功通知" , 4); } } // 邮件发送 $user_model = new UserModel(); $user_obj = $user_model ->get( $buyer_id ); if (! empty ( $user_obj )) { $email = $user_obj [ "user_email" ]; if (! empty ( $email ) && $this ->email_is_open == 1) { $template_obj = $this ->getTemplateDetail( $shop_id , "create_order" , "email" ); if (! empty ( $template_obj ) && $template_obj [ "is_enable" ] == 1) { $content = $template_obj [ "template_content" ]; $content = str_replace ( "{商场名称}" , $this ->shop_name, $content ); $content = str_replace ( "{用户名称}" , $user_name , $content ); $content = str_replace ( "{主订单号}" , $order_no , $content ); $content = str_replace ( "{订单金额}" , $order_money , $content ); $content = str_replace ( "{商品金额}" , $goods_money , $content ); $send_title = $template_obj [ "template_title" ]; $send_title = str_replace ( "{商场名称}" , $this ->shop_name, $send_title ); $send_title = str_replace ( "{用户名称}" , $user_name , $send_title ); $send_title = str_replace ( "{主订单号}" , $order_no , $send_title ); $send_title = str_replace ( "{订单金额}" , $order_money , $send_title ); $send_title = str_replace ( "{商品金额}" , $goods_money , $send_title ); $this ->createNoticeEmailRecords( $shop_id , $buyer_id , $email , $send_title , $content , 4); } } } } /** * 找回密码 * @param string $params * @return multitype:number string */ public function forgotPassword( $params =null){ $send_type = $params [ "send_type" ]; $send_param = $params [ "send_param" ]; $shop_id = $params [ "shop_id" ]; $this ->getShopNotifyInfo( $shop_id ); $rand = rand(100000,999999); $template_obj = $this ->getTemplateDetail( $shop_id , "forgot_password" , $send_type ); if ( $send_type == "email" ){ #邮箱验证 if ( $this ->email_is_open==1){ if (! empty ( $template_obj ) && $template_obj [ "is_enable" ]==1){ #发送 $content = $template_obj [ "template_content" ]; $content = str_replace ( "{验证码}" , $rand , $content ); $result =emailSend( $this ->email_host, $this ->email_id, $this ->email_pass, $this ->email_port, $this ->email_is_security, $this ->email_addr, $send_param , $template_obj [ "template_title" ], $content , $this ->shop_name); $this ->result[ "param" ]= $rand ; if ( $result ){ $this ->result[ "code" ]=0; $this ->result[ "message" ]= "发送成功!" ; } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "发送失败!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "商家没有设置找回密码的模板!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "商家没开启邮箱验证!" ; } } else { #短信验证 if ( $this ->mobile_is_open==1){ if (! empty ( $template_obj ) && $template_obj [ "is_enable" ]==1){ #发送 $sms_params = array ( "number" => $rand . "" ); $result = $this ->sendSMS( $this ->appKey, $this ->secretKey, $this ->freeSignName, json_encode( $sms_params ), $send_param , $template_obj [ "template_title" ], $this ->ali_use_type); if ( $result == '0' ) { $this ->result[ "code" ]=0; $this ->result[ "message" ]= "发送成功!" ; } else { $this ->result[ "code" ]= $result ; $this ->result[ "message" ]= "发送失败!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "商家没有设置找回密码的短信模板!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "商家没开启短信验证!" ; } } return $this ->result; } /** * 用户绑定手机号 * @param string $params */ public function bindMobile( $params =null){ $rand = rand(100000,999999); $mobile = $params [ "mobile" ]; $shop_id = $params [ "shop_id" ]; $user_id = $params [ "user_id" ]; #查询系统配置信息 $this ->getShopNotifyInfo( $shop_id ); if (! empty ( $mobile ) && $this ->mobile_is_open==1){ $template_obj = $this ->getTemplateDetail( $shop_id , "bind_mobile" , "sms" ); if (! empty ( $template_obj ) && $template_obj [ "is_enable" ]==1){ $sms_params = array ( "number" => $rand . "" , ); $this ->result[ "param" ]= $rand ; if (! empty ( $this ->appKey) && ! empty ( $this ->secretKey) && ! empty ( $this ->freeSignName) && ! empty ( $template_obj [ "template_title" ])){ $result = $this ->sendSMS( $this ->appKey, $this ->secretKey, $this ->freeSignName, json_encode( $sms_params ), $mobile , $template_obj [ "template_title" ], $this ->ali_use_type); if ( $result == '0' ) { $this ->result[ "code" ]=0; $this ->result[ "message" ]= "发送成功!" ; } else { $this ->result[ "code" ]= $result ; $this ->result[ "message" ]= "发送失败!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "短信配置信息有误!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "短信通知模板有误!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "店家没有开启短信验证" ; } return $this ->result; } /** * 用户绑定邮箱 * @param string $params */ public function bindEmail( $params =null){ $rand = rand(100000,999999); $email = $params [ "email" ]; $shop_id = $params [ "shop_id" ]; $user_id = $params [ "user_id" ]; #查询系统配置信息 $this ->getShopNotifyInfo( $shop_id ); if (! empty ( $email ) && $this ->email_is_open==1){ $template_obj = $this ->getTemplateDetail( $shop_id , "bind_email" , "email" ); if (! empty ( $template_obj ) && $template_obj [ "is_enable" ]==1){ $content = $template_obj [ "template_content" ]; $content = str_replace ( "{验证码}" , $rand , $content ); $this ->result[ "param" ]= $rand ; if (! empty ( $this ->email_host) && ! empty ( $this ->email_id) && ! empty ( $this ->email_pass) && ! empty ( $this ->email_addr)){ $result =emailSend( $this ->email_host, $this ->email_id, $this ->email_pass, $this ->email_port, $this ->email_is_security, $this ->email_addr, $email , $template_obj [ "template_title" ], $content , $this ->shop_name); if ( $result ){ $this ->result[ "code" ]=0; $this ->result[ "message" ]= "发送成功!" ; } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "发送失败!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "邮箱配置信息有误!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "邮箱通知模板有误!" ; } } else { $this ->result[ "code" ]=-1; $this ->result[ "message" ]= "店家没有开启邮箱验证" ; } return $this ->result; } /** * 订单提醒 * @param string $params */ public function orderRemindBusiness( $params =null){ #查询系统配置信息 $this ->getShopNotifyInfo(0); if ( $this ->email_is_open==1){ $out_trade_no = $params [ "out_trade_no" ]; //订单号 $shop_id = $params [ 'shop_id' ]; $result = "" ; $user_name = "" ; if (! empty ( $out_trade_no )){ //获取订单详情 $ns_order = new NsOrderModel(); $order_detial = $ns_order ->getInfo([ "out_trade_no" => $out_trade_no ]); //邮箱提醒 $template_email_obj = $this ->getTemplateDetail( $shop_id , "order_remind" , "email" , "business" ); $email_array = explode ( ',' , $template_email_obj [ 'notification_mode' ]); //获取要提醒的人 if (! empty ( $email_array ) && $template_email_obj [ "is_enable" ] == 1){ $content = $template_email_obj [ "template_content" ]; $content = str_replace ( "{商场名称}" , $this ->shop_name, $content ); $content = str_replace ( "{用户名称}" , $order_detial [ 'user_name' ], $content ); $content = str_replace ( "{主订单号}" , $order_detial [ 'order_no' ], $content ); $content = str_replace ( "{订单金额}" , $order_detial [ 'order_money' ], $content ); $send_title = $template_email_obj [ "template_title" ]; $send_title = str_replace ( "{商场名称}" , $this ->shop_name, $send_title ); $send_title = str_replace ( "{用户名称}" , $order_detial [ 'user_name' ], $send_title ); $send_title = str_replace ( "{主订单号}" , $order_detial [ 'order_no' ], $send_title ); $send_title = str_replace ( "{订单金额}" , $order_detial [ 'order_money' ], $send_title ); foreach ( $email_array as $v ){ $this ->createNoticeEmailRecords( $shop_id , 0, $v , $send_title , $content , 7); } } //短信提醒 $template_sms_obj = $this ->getTemplateDetail( $shop_id , "order_remind" , "sms" , "business" ); $mobile_array = explode ( ',' , $template_sms_obj [ 'notification_mode' ]); //获取要提醒的人 if (! empty ( $mobile_array ) && $template_sms_obj [ "is_enable" ] == 1){ $sms_params = array ( "shop_name" => $this ->shop_name, "user_name" => $order_detial [ 'user_name' ], "order_no" => $order_detial [ 'order_no' ], "order_money" => $order_detial [ 'order_money' ], "shopname" => $this ->shop_name, "username" => $order_detial [ 'user_name' ], "orderno" => $order_detial [ 'order_no' ], "ordermoney" => $order_detial [ 'order_money' ] ); foreach ( $mobile_array as $v ){ $this ->createNoticeSmsRecords( $template_sms_obj , $shop_id , 0, $v , $sms_params , "订单提醒-商家通知" , 7); } } } } } /** * 订单退款提醒 * @param string $params */ public function orderRefoundBusiness( $params =null){ #查询系统配置信息refund_order $this ->getShopNotifyInfo(0); if ( $this ->email_is_open==1){ $order_id = $params [ "order_id" ]; //订单id $shop_id = $params [ 'shop_id' ]; $result = "" ; $user_name = "" ; if (! empty ( $order_id )){ //获取订单详情 $ns_order = new NsOrderModel(); $order_detial = $ns_order ->getInfo([ "order_id" => $order_id ]); //邮箱提醒 $template_email_obj = $this ->getTemplateDetail( $shop_id , "refund_order" , "email" , "business" ); $email_array = explode ( ',' , $template_email_obj [ 'notification_mode' ]); //获取要提醒的人 if (! empty ( $email_array ) && $template_email_obj [ "is_enable" ] == 1){ $content = $template_email_obj [ "template_content" ]; $content = str_replace ( "{商场名称}" , $this ->shop_name, $content ); $content = str_replace ( "{用户名称}" , $order_detial [ 'user_name' ], $content ); $content = str_replace ( "{主订单号}" , $order_detial [ 'order_no' ], $content ); $content = str_replace ( "{订单金额}" , $order_detial [ 'order_money' ], $content ); $send_title = $template_email_obj [ "template_title" ]; $send_title = str_replace ( "{商场名称}" , $this ->shop_name, $send_title ); $send_title = str_replace ( "{用户名称}" , $order_detial [ 'user_name' ], $send_title ); $send_title = str_replace ( "{主订单号}" , $order_detial [ 'order_no' ], $send_title ); $send_title = str_replace ( "{订单金额}" , $order_detial [ 'order_money' ], $send_title ); foreach ( $email_array as $v ){ $this ->createNoticeEmailRecords( $shop_id , 0, $v , $send_title , $content , 6); } } //短信提醒 $template_sms_obj = $this ->getTemplateDetail( $shop_id , "refund_order" , "sms" , "business" ); $mobile_array = explode ( ',' , $template_sms_obj [ 'notification_mode' ]); //获取要提醒的人 if (! empty ( $mobile_array ) && $template_sms_obj [ "is_enable" ] == 1){ $sms_params = array ( "shop_name" => $this ->shop_name, "user_name" => $order_detial [ 'user_name' ], "order_no" => $order_detial [ 'order_no' ], "order_money" => $order_detial [ 'order_money' ], "shopname" => $this ->shop_name, "username" => $order_detial [ 'user_name' ], "orderno" => $order_detial [ 'order_no' ], "ordermoney" => $order_detial [ 'order_money' ] ); foreach ( $mobile_array as $v ){ $this ->createNoticeSmsRecords( $template_sms_obj , $shop_id , 0, $v , $sms_params , "订单退货提醒-商家通知" , 6); } } } } } /** * 用户充值余额商家提醒 */ public function rechargeSuccessBusiness( $params =null){ #查询系统配置信息 $this ->getShopNotifyInfo(0); if ( $this ->email_is_open==1){ $out_trade_no = $params [ "out_trade_no" ]; //订单号 $shop_id = $params [ 'shop_id' ]; $user = new UserModel(); $user_name = $user ->getInfo([ "uid" => $params [ 'uid' ]], "nick_name" )[ "nick_name" ]; $result = "" ; if (! empty ( $out_trade_no )){ //获取支付详情 $pay = new NsOrderPaymentModel(); $order_payment = $pay ->getInfo([ "out_trade_no" => $out_trade_no ]); //邮箱提醒 $template_email_obj = $this ->getTemplateDetail( $shop_id , "recharge_success" , "email" , "business" ); $email_array = explode ( ',' , $template_email_obj [ 'notification_mode' ]); //获取要提醒的人 if (! empty ( $email_array ) && $template_email_obj [ "is_enable" ] == 1){ $content = $template_email_obj [ "template_content" ]; $content = str_replace ( "{商场名称}" , $this ->shop_name, $content ); $content = str_replace ( "{用户名称}" , $user_name , $content ); $content = str_replace ( "{充值金额}" , $order_payment [ 'pay_money' ], $content ); $send_title = $template_email_obj [ "template_title" ]; $send_title = str_replace ( "{商场名称}" , $this ->shop_name, $send_title ); $send_title = str_replace ( "{用户名称}" , $user_name , $send_title ); $send_title = str_replace ( "{充值金额}" , $order_payment [ 'pay_money' ], $send_title ); foreach ( $email_array as $v ){ $this ->createNoticeEmailRecords( $shop_id , 0, $v , $send_title , $content , 8); } } //短信提醒 $template_sms_obj = $this ->getTemplateDetail( $shop_id , "recharge_success" , "sms" , "business" ); $mobile_array = explode ( ',' , $template_sms_obj [ 'notification_mode' ]); //获取要提醒的人 if (! empty ( $mobile_array ) && $template_sms_obj [ "is_enable" ] == 1){ $sms_params = array ( "shop_name" => $this ->shop_name, "user_name" => $user_name , "recharge_money" => $order_payment [ 'pay_money' ], "shopname" => $this ->shop_name, "username" => $user_name , "rechargemoney" => $order_payment [ 'pay_money' ] ); foreach ( $mobile_array as $v ){ $this ->createNoticeSmsRecords( $template_sms_obj , $shop_id , 0, $v , $sms_params , "余额充值-商家通知" , 8); } } } } } /** * 用户充值余额用户提醒 */ public function rechargeSuccessUser( $params =null){ #查询系统配置信息 $this ->getShopNotifyInfo(0); $out_trade_no = $params [ "out_trade_no" ]; //订单号 $shop_id = $params [ 'shop_id' ]; $user = new UserModel(); $user_info = $user ->getInfo([ "uid" => $params [ 'uid' ]], "*" ); $user_name = $user_info [ "nick_name" ]; $user_tel = $user_info [ "user_tel" ]; $user_email = $user_info [ "user_email" ]; $result = "" ; if (! empty ( $out_trade_no )){ //获取支付详情 $pay = new NsOrderPaymentModel(); $order_payment = $pay ->getInfo([ "out_trade_no" => $out_trade_no ]); //邮箱提醒 $template_email_obj = $this ->getTemplateDetail( $shop_id , "recharge_success" , "email" , "user" ); $email_array = explode ( ',' , $template_email_obj [ 'notification_mode' ]); //获取要提醒的人 if (! empty ( $email_array ) && $template_email_obj [ "is_enable" ] == 1){ $content = $template_email_obj [ "template_content" ]; $content = str_replace ( "{商场名称}" , $this ->shop_name, $content ); $content = str_replace ( "{用户名称}" , $user_name , $content ); $content = str_replace ( "{充值金额}" , $order_payment [ 'pay_money' ], $content ); $send_title = $template_email_obj [ "template_title" ]; $send_title = str_replace ( "{商场名称}" , $this ->shop_name, $send_title ); $send_title = str_replace ( "{用户名称}" , $user_name , $send_title ); $send_title = str_replace ( "{充值金额}" , $order_payment [ 'pay_money' ], $send_title ); $this ->createNoticeEmailRecords( $shop_id , $user_info [ "uid" ], $user_email , $send_title , $content , 1); } //短信提醒 $template_sms_obj = $this ->getTemplateDetail( $shop_id , "recharge_success" , "sms" , "user" ); $mobile_array = explode ( ',' , $template_sms_obj [ 'notification_mode' ]); //获取要提醒的人 if (! empty ( $mobile_array ) && $template_sms_obj [ "is_enable" ] == 1){ $sms_params = array ( "shop_name" => $this ->shop_name, "user_name" => $user_name , "recharge_money" => $order_payment [ 'pay_money' ], "shopname" => $this ->shop_name, "username" => $user_name , "rechargemoney" => $order_payment [ 'pay_money' ] ); $this ->createNoticeSmsRecords( $template_sms_obj , $shop_id , $user_info [ "uid" ], $user_tel , $sms_params , "用户余额充值" , 1); } } } /** * 添加短信记录 * @param unknown $template_obj * @param unknown $shop_id * @param unknown $buyer_id * @param unknown $mobile * @param unknown $sms_params * @param unknown $title * @param unknown $records_type */ private function createNoticeSmsRecords( $template_obj , $shop_id , $buyer_id , $mobile , $sms_params , $title , $records_type ){ $notice_service = new Notice(); $send_config = array ( "appkey" => $this ->appKey, "secret" => $this ->secretKey, "signName" => $this ->freeSignName, "template_code" => $template_obj [ "template_title" ], "sms_type" => $this ->ali_use_type ); $notice_service ->createNoticeRecords( $shop_id , $buyer_id , 1, $mobile , $title , json_encode( $sms_params ), $records_type , json_encode( $send_config )); } private function createNoticeEmailRecords( $shop_id , $buyer_id , $mobile , $send_title , $content , $records_type ){ $notice_service = new Notice(); $send_config = array ( "email_host" => $this ->email_host, "email_id" => $this ->email_id, "email_pass" => $this ->email_pass, "email_port" => $this ->email_port, "email_is_security" => $this ->email_is_security, "email_addr" => $this ->email_addr, "shopName" => $this ->shop_name, ); $notice_service ->createNoticeRecords( $shop_id , $buyer_id , 2, $mobile , $send_title , $content , $records_type , json_encode( $send_config )); } } ?> |
最后我们在项目\application\shop\controller下创建Smsbao.php文件,修改模板字段的长度,将以下代码复制到Smsbao.php文件中:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<?php namespace app\shop\controller; use think\Controller; use think\Db; class Smsbao extends Controller { /** * 修改长度为255 */ public function index() { Db::query( "alter table sys_notice_template modify column template_title varchar(255) not null" ); echo '短信宝插件安装成功' ; } } |
好了,经过以上的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行发送测试:
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的NIU_SHOP商城系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类