b.liu | 4e243dc | 2023-11-27 11:20:00 +0800 | [diff] [blame] | 1 | #include "lynq_qser_sms.h" |
| 2 | #include "mbtk_type.h" |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 3 | #include "mbtk_pdu_sms.h" |
| 4 | #include "mbtk_info_api.h" |
| 5 | #include "lynq_sms.h" |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 6 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | |
| 11 | |
| 12 | #define TELEPHONE_NUM_MAX 16 |
| 13 | #define MSM_NUMBER_MAX 1024+1 |
| 14 | #define RES_NUM_MIN 128 |
| 15 | |
| 16 | |
| 17 | #define DSC_to_msg(DSC) (DSC == 0 ? "Bit7" : (DSC == 1 ? "Bit8" : "UCS2")) |
| 18 | |
| 19 | static mbtk_info_handle_t* sms_info_handle = NULL; |
| 20 | static char sms_center_address[128] = {0}; |
| 21 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 22 | typedef struct |
| 23 | { |
| 24 | QSER_SMS_RxMsgHandlerFunc_t handlerPtr; |
| 25 | void* contextPtr; |
| 26 | } lynq_sms_cb_func; |
| 27 | |
| 28 | static lynq_sms_cb_func lynq_sms_func_cb_handle; |
| 29 | |
| 30 | sms_client_handle_type g_sms_val = -1; |
| 31 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 32 | |
| 33 | void lynq_sms_state_change_cb(const void* data, int data_len) |
| 34 | { |
| 35 | LOGV("sms_state_change_cb()----------start\n"); |
| 36 | uint8 *ptr = (uint8*)data; |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 37 | //printf("3sms_state_change_cb() : %s\n", ptr); |
| 38 | |
| 39 | if (!strncmp("+CMT:", ptr, 5))//丢弃无用消息 |
| 40 | return ; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 41 | |
| 42 | struct SMS_Struct s = PDUDecoding(ptr); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 43 | /* |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 44 | printf("服务中心地址: %s\n", s.SCA); |
| 45 | printf("发送方地址: %s\n", s.OA); |
| 46 | printf("服务中心时间戳: %s\n", s.SCTS); |
| 47 | printf("消息内容: %s\n", s.UD); |
| 48 | printf("数据编码方案: %s\n", DSC_to_msg(s.DCS)); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 49 | */ |
| 50 | QSER_SMS_Msg_t* tmp_data = NULL; |
| 51 | |
| 52 | tmp_data = (QSER_SMS_Msg_t*)malloc(sizeof(QSER_SMS_Msg_t)); |
| 53 | memset(tmp_data,0x00, sizeof(QSER_SMS_Msg_t)); |
| 54 | |
| 55 | tmp_data->format = s.DCS; |
| 56 | //printf("t数据编码方案: %d\n", tmp_data->format); |
| 57 | memcpy(tmp_data->src_addr, s.OA, strlen(s.OA)); |
| 58 | //printf("t发送方地址: %s\n", tmp_data->src_addr); |
| 59 | memcpy(tmp_data->timestamp, s.SCTS, strlen(s.SCTS)); |
| 60 | //printf("t服务中心时间戳: %s\n", tmp_data->timestamp); |
| 61 | tmp_data->sms_data_len = strlen(s.UD); |
| 62 | //printf("t消息内容长度: %d\n", tmp_data->sms_data_len); |
| 63 | memcpy(tmp_data->sms_data, s.UD, strlen(s.UD)); |
| 64 | //printf("t消息内容: %s\n", tmp_data->sms_data); |
| 65 | |
| 66 | lynq_sms_func_cb_handle.handlerPtr(tmp_data, NULL); |
| 67 | |
| 68 | free(tmp_data); |
| 69 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | |
| 73 | int qser_sms_client_init(sms_client_handle_type *ph_sms)//out |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 74 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 75 | //UNUSED(ph_sms); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 76 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 77 | if(sms_info_handle == NULL) |
| 78 | { |
| 79 | sms_info_handle = mbtk_info_handle_get(); |
| 80 | if(sms_info_handle) |
| 81 | { |
| 82 | printf("creat sms_info_handle is success\n"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 83 | *ph_sms = sms_info_handle->client_fd; |
| 84 | g_sms_val = sms_info_handle->client_fd; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 85 | } |
| 86 | else |
| 87 | { |
| 88 | printf("creat sms_info_handle is fail\n"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 89 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 93 | return 0; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 94 | } |
| 95 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 96 | int qser_sms_client_deinit(sms_client_handle_type h_sms)//in |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 97 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 98 | //UNUSED(h_sms); |
| 99 | if (h_sms != g_sms_val || g_sms_val == -1) |
| 100 | { |
| 101 | printf("handle NULL\n"); |
| 102 | return -1; |
| 103 | } |
| 104 | |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 105 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 106 | if(sms_info_handle) |
| 107 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 108 | mbtk_info_handle_free(&sms_info_handle); |
| 109 | printf("deinit sms_info_handle is succuess\n"); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 110 | } |
| 111 | else |
| 112 | { |
| 113 | printf("deinit sms_info_handle is fail\n"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 114 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 115 | } |
| 116 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 117 | return 0; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 118 | } |
| 119 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 120 | int qser_sms_send_sms(sms_client_handle_type h_sms, QSER_sms_info_t *pt_sms_info)//in in 发送短信的内容、目的号码 |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 121 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 122 | //UNUSED(h_sms); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 123 | //UNUSED(pt_sms_info); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 124 | if (h_sms != g_sms_val || g_sms_val == -1) |
| 125 | { |
| 126 | printf("handle NULL\n"); |
| 127 | return -1; |
| 128 | } |
| 129 | |
| 130 | |
| 131 | if (pt_sms_info == NULL) |
| 132 | { |
| 133 | printf("QSER_sms_info_t NULL\n"); |
| 134 | return -1; |
| 135 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 136 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 137 | if(sms_info_handle == NULL) |
| 138 | { |
| 139 | printf("qser_sms_send_sms sms_info_handle NULL\n"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 140 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | //QSER_sms_info_t get_sms_info; |
| 144 | |
| 145 | //get_sms_info.format = pt_sms_info->format;//格式,7/8/UCS2,分别对应英文/彩铃图片/中文 |
| 146 | //get_sms_info.mode = pt_sms_info->mode;//指定存储位置 |
| 147 | //get_sms_info.sms_data = pt_sms_info->sms_data;//数据 |
| 148 | //get_sms_info.sms_data_len = pt_sms_info->sms_data_len;//数据长度 |
| 149 | //get_sms_info.src_addr = pt_sms_info->src_addr;//电话号码 |
| 150 | //get_sms_info.storage = pt_sms_info->storage;//存储位置 |
| 151 | //get_sms_info.storage_index = pt_sms_info->storage_index;//索引 |
| 152 | //get_sms_info.timestamp = pt_sms_info->timestamp;//时间戳 |
| 153 | //get_sms_info.type = pt_sms_info->type;//起始/结束/广播 |
| 154 | //get_sms_info.user_data_head = pt_sms_info->user_data_head;//长短信用户头部信息 |
| 155 | //get_sms_info.user_data_head_valid = pt_sms_info->user_data_head_valid;//是否是长短信 |
| 156 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 157 | uint8_t *phone_num = NULL, *data = NULL; |
| 158 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 159 | char cmgs[MSM_NUMBER_MAX] = {0}; |
| 160 | char resp[RES_NUM_MIN] = {0}; |
| 161 | char pdu_data[512] = {0}; |
| 162 | char phone_lenth[10] = {0}; |
| 163 | char *p = pdu_data; |
| 164 | int mode = 0; |
| 165 | int err = 0; |
| 166 | int i = 0; |
| 167 | |
| 168 | data = pt_sms_info->sms_data; |
| 169 | |
| 170 | phone_num = pt_sms_info->src_addr; |
| 171 | |
| 172 | if (pt_sms_info->format == 0)//7 |
| 173 | mode = 1; |
| 174 | else if (pt_sms_info->format == 1)//8 |
| 175 | return SMS_ERR; |
| 176 | else if (pt_sms_info->format == 2)//USC2 |
| 177 | mode = 0; |
| 178 | else |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 179 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 180 | |
| 181 | if(data == NULL) |
| 182 | { |
| 183 | printf("qser_sms_send_sms data NULL\n"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 184 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | if(phone_num == NULL) |
| 188 | { |
| 189 | printf("qser_sms_send_sms phone_num NULL\n"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 190 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 191 | } |
| 192 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 193 | |
| 194 | if(strlen(data) > 512 || strlen(data) == 0 || strlen(phone_num) == 0) |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 195 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 196 | printf("strlen(telephony_num):%d\n", strlen(phone_num)); |
| 197 | printf("strlen(msg):%d\n", strlen(data)); |
| 198 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 199 | } |
| 200 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 201 | if (mode == 0)// PDU |
| 202 | { |
| 203 | #if 1 |
| 204 | if (sms_center_address[0] == '\0') |
| 205 | { |
| 206 | memset(sms_center_address, 0, sizeof(sms_center_address)); |
| 207 | memcpy(sms_center_address, "+8613800280500", strlen("+8613800280500")); |
| 208 | } |
| 209 | |
| 210 | printf("phone_num:%s\n", phone_num); |
| 211 | printf("sms_center_address:%s\n", sms_center_address); |
| 212 | printf("data:%s\n", data); |
| 213 | |
| 214 | char* pdu = NULL; |
| 215 | char* smsc = SCAEncoding(sms_center_address); |
| 216 | struct PDUS *pdus = PDUEncoding(sms_center_address,phone_num, data, NULL); |
| 217 | |
| 218 | for (i = 0; i < pdus->count; i++) |
| 219 | { |
| 220 | printf("第 %d 条:\n", i + 1); |
| 221 | printf("%s\n", pdus->PDU[i]); |
| 222 | pdu = pdus->PDU[i]; |
| 223 | } |
| 224 | |
| 225 | sprintf(p, "%s",smsc); |
| 226 | printf("pdu_data:%s\n", pdu_data); |
| 227 | sprintf(p+strlen(p), "%s", pdu); |
| 228 | printf("pdu_data:%s\n",pdu_data); |
| 229 | |
| 230 | //sprintf(cmgs,"%d,%s",strlen(pdu_data), pdu_data); |
| 231 | int t = strlen(pdu_data); |
| 232 | sprintf(cmgs,"%d,%s",(t-18)/2, pdu_data); |
| 233 | printf("cmgs:%s\n", cmgs); |
| 234 | #else |
| 235 | char *tmp_t = "0891683108200805F011000D91688189914026F3000800044F60597D"; |
| 236 | sprintf(cmgs,"%d,%s",19,tmp_t); |
| 237 | printf("cmgs:%s\n", cmgs); |
| 238 | #endif |
| 239 | |
| 240 | memset(resp, 0, sizeof(resp)); |
| 241 | |
| 242 | err = mbtk_sms_cmgf_set(sms_info_handle, mode); |
| 243 | if(err) |
| 244 | { |
| 245 | printf("cmgf set error : %d\n", err); |
| 246 | } |
| 247 | else |
| 248 | { |
| 249 | printf("cmgf set success\n"); |
| 250 | } |
| 251 | |
| 252 | err = mbtk_sms_cmgs_set(sms_info_handle, cmgs, resp); |
| 253 | if(err) |
| 254 | { |
| 255 | printf("Error : %d\n", err); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 256 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 257 | } |
| 258 | else |
| 259 | { |
| 260 | printf("cmgs set success . resp:%s\n", resp); |
| 261 | } |
| 262 | } |
| 263 | else if (mode == 1) // text |
| 264 | { |
| 265 | err = mbtk_sms_cmgf_set(sms_info_handle, mode); |
| 266 | if(err) |
| 267 | { |
| 268 | printf("cmgf set error : %d\n", err); |
| 269 | } |
| 270 | else |
| 271 | { |
| 272 | printf("cmgf set success\n"); |
| 273 | } |
| 274 | |
| 275 | sprintf(cmgs,"%s,%s", phone_num, data); |
| 276 | printf("cmgs:%s\n", cmgs); |
| 277 | |
| 278 | memset(resp, 0, sizeof(resp)); |
| 279 | |
| 280 | err = mbtk_sms_cmgs_set(sms_info_handle, cmgs, resp); |
| 281 | if(err) |
| 282 | { |
| 283 | printf("Error : %d\n", err); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 284 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 285 | } |
| 286 | else |
| 287 | { |
| 288 | printf("cmgs set success . resp:%s\n", resp); |
| 289 | } |
| 290 | } |
| 291 | else |
| 292 | { |
| 293 | printf("Error : mode\n"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 294 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 295 | } |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 296 | |
| 297 | return 0; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 298 | } |
| 299 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 300 | //注册接收新短信 |
| 301 | int qser_sms_addrxmsghandler(QSER_SMS_RxMsgHandlerFunc_t handlerPtr, void* contextPtr)//in sms电话状态回调函数 in 主要是获取 上报 的内容 |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 302 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 303 | //UNUSED(handlerPtr); |
| 304 | //UNUSED(contextPtr); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 305 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 306 | if(sms_info_handle == NULL) |
| 307 | { |
| 308 | printf("qser_sms_addrxmsghandler sms_info_handle NULL\n"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 309 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | int err = mbtk_sms_cnmi_set(sms_info_handle); |
| 313 | if(err) |
| 314 | { |
| 315 | printf("set cnmi fail\n"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 316 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 317 | } |
| 318 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 319 | lynq_sms_func_cb_handle.handlerPtr = handlerPtr; |
| 320 | lynq_sms_func_cb_handle.contextPtr = contextPtr; |
| 321 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 322 | mbtk_sms_state_change_cb_reg(sms_info_handle, lynq_sms_state_change_cb); |
| 323 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 324 | return 0; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 325 | } |
| 326 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 327 | //删除短信 |
| 328 | int qser_sms_deletefromstorage(sms_client_handle_type h_sms, QSER_sms_storage_info_t *pt_sms_storage)//in in 删除短信的信息 |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 329 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 330 | //UNUSED(h_sms); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 331 | //UNUSED(pt_sms_storage); |
| 332 | char cmgd[128] = {0}; |
| 333 | int err = 0; |
| 334 | int id_x = -1; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 335 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 336 | if (h_sms != g_sms_val || g_sms_val == -1) |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 337 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 338 | printf("handle NULL\n"); |
| 339 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 340 | } |
| 341 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 342 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 343 | if(pt_sms_storage == NULL) |
| 344 | { |
| 345 | printf("qser_sms_deletefromstorage pt_sms_storage NULL\n"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 346 | return -1; |
| 347 | } |
| 348 | |
| 349 | if(sms_info_handle == NULL) |
| 350 | { |
| 351 | printf("qser_sms_deletefromstorage sms_info_handle NULL\n"); |
| 352 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | id_x = pt_sms_storage->storage_idx;//获取idx的值 |
| 356 | |
| 357 | if(id_x == -1) //delete all |
| 358 | { |
| 359 | memcpy(cmgd, ",4", strlen(",4")); |
| 360 | } |
| 361 | else |
| 362 | { |
| 363 | sprintf(cmgd,"%d",id_x); |
| 364 | } |
| 365 | |
| 366 | printf("cmgd:%s\n", cmgd); |
| 367 | |
| 368 | err = mbtk_sms_cmgd_set(sms_info_handle, cmgd); |
| 369 | if(err) |
| 370 | { |
| 371 | printf("qser_sms_deletefromstorage Error : %d\n", err); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 372 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 373 | } |
| 374 | else |
| 375 | { |
| 376 | printf("qser_sms_deletefromstorage set success\n"); |
| 377 | } |
| 378 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 379 | return 0; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 380 | } |
| 381 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 382 | //获取短信中心号码 |
| 383 | int qser_sms_getsmscenteraddress( sms_client_handle_type h_sms,QSER_sms_service_center_cfg_t *set_sca_cfg)//in out |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 384 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 385 | //UNUSED(h_sms); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 386 | //UNUSED(set_sca_cfg); |
| 387 | char sms_center_addree[254] = {0}; |
| 388 | int len_t; |
| 389 | char *p1, *p2 ,*substr; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 390 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 391 | if (h_sms != g_sms_val || g_sms_val == -1) |
| 392 | { |
| 393 | printf("handle NULL\n"); |
| 394 | return -1; |
| 395 | } |
| 396 | |
| 397 | |
| 398 | if (set_sca_cfg == NULL) |
| 399 | { |
| 400 | printf("QSER_sms_service_center_cfg_t NULL\n"); |
| 401 | return -1; |
| 402 | } |
| 403 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 404 | |
| 405 | if(sms_info_handle == NULL) |
| 406 | { |
| 407 | printf("qser_sms_getsmscenteraddress sms_info_handle NULL\n"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 408 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | int err = mbtk_sms_csca_get(sms_info_handle, sms_center_addree); |
| 412 | if(sms_center_addree[0] == '\0') |
| 413 | { |
| 414 | printf("qser_sms_getsmscenteraddress Error : %d\n", err); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 415 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 416 | } |
| 417 | else |
| 418 | { |
| 419 | p1 = strchr(sms_center_addree, '\"'); // 查找第一个双引号 |
| 420 | p2 = strrchr(sms_center_addree, '\"'); // 查找最后一个双引号 |
| 421 | if (p1 && p2 && p2 > p1) // 如果找到了两个双引号 |
| 422 | { |
| 423 | len_t = p2 - p1 - 1; // 计算双引号内的字符串长度 |
| 424 | char substr_t[len_t + 1]; // 定义一个新的字符串 |
| 425 | strncpy(substr_t, p1 + 1, len_t); // 复制双引号内的字符串到新的字符串中 |
| 426 | substr_t[len_t] = '\0'; // 在新的字符串末尾添加结束符 |
| 427 | //printf("双引号内的字符串为:%s\n", substr_t); // 输出结果 |
| 428 | substr = substr_t; |
| 429 | |
| 430 | memcpy(set_sca_cfg->service_center_addr, substr, strlen(substr)); |
| 431 | memcpy(sms_center_address, substr, strlen(substr)); |
| 432 | |
| 433 | printf("qser_sms_getsmscenteraddress success\n"); |
| 434 | } |
| 435 | else |
| 436 | { |
| 437 | printf("未找到双引号内的字符串\n"); // 输出结果 |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 438 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 439 | } |
| 440 | } |
| 441 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 442 | return 0; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 443 | } |
| 444 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 445 | //设置短信中心号码 |
| 446 | int qser_sms_setsmscenteraddress( sms_client_handle_type h_sms, QSER_sms_service_center_cfg_t *get_sca_cfg)//in in |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 447 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 448 | //UNUSED(h_sms); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 449 | //UNUSED(get_sca_cfg); |
| 450 | char *destNum = NULL; |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 451 | |
| 452 | if (h_sms != g_sms_val || g_sms_val == -1) |
| 453 | { |
| 454 | printf("handle NULL\n"); |
| 455 | return -1; |
| 456 | } |
| 457 | |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 458 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 459 | if(sms_info_handle == NULL) |
| 460 | { |
| 461 | printf("qser_sms_setsmscenteraddress sms_info_handle NULL\n"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 462 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | if(get_sca_cfg == NULL) |
| 466 | { |
| 467 | printf("qser_sms_setsmscenteraddress get_sca_cfg NULL\n"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 468 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | destNum = get_sca_cfg->service_center_addr; |
| 472 | |
| 473 | printf("1destNum:%s\n", destNum); |
| 474 | memset(sms_center_address, 0, sizeof(sms_center_address)); |
| 475 | memcpy(sms_center_address, destNum, strlen(destNum)); |
| 476 | |
| 477 | if (destNum == NULL) |
| 478 | { |
| 479 | printf("qser_sms_setsmscenteraddress destNum NULL\n"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 480 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | int err = mbtk_sms_csca_set(sms_info_handle, destNum); |
| 484 | if(err) |
| 485 | { |
| 486 | printf("Error : %d\n", err); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 487 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 488 | } |
| 489 | else |
| 490 | { |
| 491 | // memset(sms_center_address, 0, sizeof(sms_center_address)); |
| 492 | // memcpy(sms_center_address, destNum, strlen(destNum)); |
| 493 | printf("destNum:%s\n", destNum); |
| 494 | printf("qser_sms_setsmscenteraddress success\n"); |
| 495 | } |
| 496 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame^] | 497 | return 0; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 498 | } |
| 499 | |